How to replace the \u00e2\u0080\u0099 this string

2019-08-09 08:49发布

I got a value from server and i stored it in NSString object. In that string "'" is replaced with \u00e2\u0080\u0099. I tried to replace this by using replaceOccurencesOfString. But it shows an error. Herewith i displayed my code and error.

 [mutstr_Description replaceOccurrencesOfString:@"\u00e2\u0080\u0099" withString:@"'" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutstr_Description length])];

enter image description here

Help to solve this issue.

1条回答
冷血范
2楼-- · 2019-08-09 09:16

Assuming your string actually has the literal characters \, u, 0, etc., you need to do this:

[mutstr_Description replaceOccurrencesOfString:@"\\u00e2\\u0080\\u0099" withString:@"'" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutstr_Description length])];

You need to escape the backslashes.

Update - perhaps your string actually has those control characters. Try this:

NSString *controlChars = [NSString stringWithFormat:@"%C%C%C", 0xe2, 0x80, 0x99];
[mutstr_Description replaceOccurrencesOfString:controlChars withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [mutstr_Description length])];
查看更多
登录 后发表回答