本文介绍了“不完全通用字符名称”与stringWithUTF8String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<$ p>
NSString * s = [NSString stringWithUTF8String: \U0627\U0644\U0641\U0631\U0646];
NSLog(@%@,s);
我得到编译错误:
不完整的通用字符名称
注意,它有时工作正常:
NSString * UAE = [NSString stringWithUTF8String:\U0627\U0644\U0641\U0631\U0646] ;
NSLog(@%@,UAE);
和输出:
الامارات
请帮助。
解决方案
\U和\u不是一回事。 \U转义需要8(十六进制)数字而不是4。
这应该工作:
NSString * s = [NSString stringWithUTF8String:\\\ا\\\ل\\\ف\\\ر\\\ن];
when i try to convert form utf-8 string to NSString like so:
NSString *s = [NSString stringWithUTF8String:"\U0627\U0644\U0641\U0631\U0646"];
NSLog(@"%@", s);
i get the compile error:
incomplete universal character name
note that it sometime just works fine:
NSString *UAE = [NSString stringWithUTF8String:"\U0627\U0644\U0641\U0631\U0646"];
NSLog(@"%@", UAE);
and the output:
الامارات
so why is that happening? please help.
解决方案
\U and \u are not the same thing. The \U escape expects 8 (hex) digits instead of 4.
This should work:
NSString *s = [NSString stringWithUTF8String:"\u0627\u0644\u0641\u0631\u0646"];
这篇关于“不完全通用字符名称”与stringWithUTF8String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!