NSString中的另一种UTF8解码 [英] Different kind of UTF8 decoding in NSString
问题描述
我已经搜索了很多有关UTF8解码的信息,但尚未找到答案.
I have searched a lot about UTF8 decoding, but not found the answer yet.
我从我的NSXMLParser收到一个UTF-8解码NSString:
I receive an UTF-8 decode NSString from my NSXMLParser:
NSString *tempString = @"Test message readability is óké";
某种程度上,我找不到将编码后的文本更改为的方法:
In someway I can't find the way to change this encoded text to:
Test message readability is óké
我可以说出我尝试过的所有选项,但我认为那不是必需的.可以帮忙吗?
I could tell all the options I tried but I don't think that should be necessary. Could please some help?
Thnx!
推荐答案
NSXMLParser
将使用XML指定的字符编码来处理文本.我相信在您的情况下,XML不会明确指定UTF-8.
The NSXMLParser
will treat the text using the character encoding that the XML specifies. I believe in your case the XML do not specify UTF-8 explicitly.
该文本似乎是ISO Latin1.如果您不能对生成XML的服务器做任何事情,则可以应用此技巧:
The text seems to be ISO Latin 1. If you can not do anything about the server generating the XML then you can apply this hack:
char* tempString = [string cStringUsingEncoding:NSISOLatin1StringEncoding];
string = [NSString stringWithUTF8String:tempString];
我已经通过在GDB提示符下进行测试来验证了这种方法是否可行:
I have verified that this works by testing this from the GDB prompt:
po [NSString stringWithUTF8String:(char*)[@"Test message readability is óké" cStringUsingEncoding:5]]
这篇关于NSString中的另一种UTF8解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!