如何在iOS中将\u00e2\u0080\u0099这个字符串替换成' [英] How to replace the \u00e2\u0080\u0099 this string into ' in iOS

查看:65
本文介绍了如何在iOS中将\u00e2\u0080\u0099这个字符串替换成'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器获取了一个值并将其存储在 NSString 对象中.在该字符串中,'"被替换为 \u00e2\u0080\u0099.我试图通过使用 replaceOccurencesOfString 来替换它.但它显示一个错误.在此我显示了我的代码和错误.

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

帮助解决这个问题.

推荐答案

假设您的字符串实际上具有文字字符 \, u, 0> 等,你需要这样做:

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

您需要转义反斜杠.

更新 - 也许您的字符串实际上具有那些控制字符.试试这个:

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

这篇关于如何在iOS中将\u00e2\u0080\u0099这个字符串替换成'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆