Objective C,如何解码这个 UTF16 字符串? [英] Objective C, how to decode this UTF16 string?
本文介绍了Objective C,如何解码这个 UTF16 字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的字符串,
I have a string like this,
NSString *u = @"%u9ED1%u9AD4";
我需要解码这个 UTF16 字符串才能得到下面的 unicode 实体:
I need to decode this UTF16 string to obtain the unicode entity below:
黑體
我正在尝试:
NSData *fontNameData = [@"%u9ED1%u9AD4" dataUsingEncoding:NSUTF16StringEncoding];
NSString *l = [[NSString alloc] initWithData:fontNameData encoding:NSUTF16StringEncoding];
NSLog (l);
似乎不起作用.我究竟做错了什么?非常感谢您的帮助
Doesn't seem to work. What am I doing wrong? Will greatly appreciate the help
推荐答案
像这样:
NSString *u = @"%u9ED1%u9AD4";
u = [u stringByReplacingOccurrencesOfString:@"%u" withString:@"\\u"];
u = [u stringByApplyingTransform:@"Any-Hex" reverse:YES];
NSLog(@"%@", u); // 黑體
这篇关于Objective C,如何解码这个 UTF16 字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文