如何将\u00e2\u0080\u0099此字符串替换为';在iOS中
我从服务器获取了一个值,并将其存储在NSString对象中。在该字符串中,将“'”替换为\u00e2\u0080\u0099。我尝试使用replaceOccurrenceSofString替换此项。但它显示了一个错误。在此,我显示了我的代码和错误如何将\u00e2\u0080\u0099此字符串替换为';在iOS中,ios,objective-c,xcode,nsstring,nsstringencoding,Ios,Objective C,Xcode,Nsstring,Nsstringencoding,我从服务器获取了一个值,并将其存储在NSString对象中。在该字符串中,将“'”替换为\u00e2\u0080\u0099。我尝试使用replaceOccurrenceSofString替换此项。但它显示了一个错误。在此,我显示了我的代码和错误 [mutstr_Description replaceOccurrencesOfString:@"\u00e2\u0080\u0099" withString:@"'" options:NSCaseInsensitiveSearch range:NS
[mutstr_Description replaceOccurrencesOfString:@"\u00e2\u0080\u0099" withString:@"'" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutstr_Description length])];
帮助解决此问题。假设您的字符串实际包含文本字符
\
、u
、0
等,则需要执行以下操作:
[mutstr_Description replaceOccurrencesOfString:@"\\u00e2\\u0080\\u0099" withString:@"'" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [mutstr_Description length])];
你需要避开反斜杠
更新-可能您的字符串实际上包含这些控制字符。试试这个:
NSString *controlChars = [NSString stringWithFormat:@"%C%C%C", 0xe2, 0x80, 0x99];
[mutstr_Description replaceOccurrencesOfString:controlChars withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [mutstr_Description length])];
我试过你说的了。现在没有显示错误。但内容并没有被取代。[mutstr_Description replaceCurrencesofString:@“\\u002\\u0080\\u0099”带字符串:@“'”选项:NSCaseInsensitiveSearch范围:NSMakeRange(0,[mutstr_Description length]);