Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将\u00e2\u0080\u0099此字符串替换为';在iOS中_Ios_Objective C_Xcode_Nsstring_Nsstringencoding - Fatal编程技术网

如何将\u00e2\u0080\u0099此字符串替换为';在iOS中

如何将\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

我从服务器获取了一个值,并将其存储在NSString对象中。在该字符串中,将“'”替换为\u00e2\u0080\u0099。我尝试使用replaceOccurrenceSofString替换此项。但它显示了一个错误。在此,我显示了我的代码和错误

 [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]);