[英]String to UTF8 Char Conversion in Objective-C
I'm trying to save an UTF8 char to a string and print it to a label. 我正在尝试将UTF8字符保存到字符串并将其打印到标签。
If I hard code it works fine: 如果我进行硬编码,则可以正常工作:
NSString *param = @"\uf02e";
NSLog(param);
Result: 结果:
2012-10-24 16:09:56.522 i[22996:12c03]
By the way if I'm saving the char to a string I can't go back. 顺便说一句,如果我将char保存到字符串中,就无法返回。
NSString *myString = [NSString stringWithFormat:@"%@",[item objectForKey:content]];
NSLog(myString);
Result: 结果:
2012-10-24 16:18:47.289 i[23105:12c03] \uf02e
Any solution for this? 有什么解决办法吗? Thanks.
谢谢。
EDIT 编辑
item is an NSDictionary and [item objectForKey:content] is a string. item是一个NSDictionary,[item objectForKey:content]是一个字符串。
NSString *param = @"\uf02e";
NSDictionary* item = [NSDictionary dictionaryWithObject: param forKey: @"key"];
NSString *myString = [NSString stringWithFormat:@"%@",[item objectForKey: @"key"]];
NSLog(myString);
Works fine for me. 对我来说很好。 So the error is in the value, that you're inserting into the dictionary.
因此,错误在于您要插入字典中的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.