문제

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.

도움이 되었습니까?

해결책

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])];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top