将Unicode字符转换为NSString [英] Convert Unicode character to NSString
问题描述
我收到了来自webservice的字符串,其中包含Unicode字符。我想将其转换为纯NSString。那我怎么能这样做?
I have received string from webservice which contains Unicode character. I want to convert that To plain NSString. so How can i do that?
ex:这不是你的自行车
ex: "This isn\u0092t your bike"
那么如何可以删除unicode并用其相同的特殊符号替换它。
So how can remove unicode and replace it with its equal special symbol characted.
输出结果为:这不是你的自行车
The output would be : "This isn't your bike"
推荐答案
char cString[] = "This isn\u2019t your bike";
NSData *data = [NSData dataWithBytes:cString length:strlen(cString)];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"result string: %@", string);
这应该有效。
更新FOR评论:
所有字体都不支持您指定的unicode字符。
The unicode character specified by you is not supported in all fonts.
http://www.fileformat .info / info / unicode / char / 92 / fontsupport.htm
但这个确实如此。
http://www.fileformat.info/info/unicode/char/2019/fontsupport .htm
这就是它抛出错误的原因。
Thats why it throws an error.
这篇关于将Unicode字符转换为NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!