如何将Unicode值转换为字符串目标C.

时间:2014-07-26 23:46:30

标签: objective-c unicode

我希望获得字符的实际unicode值,并将其放入转义字符串中。我将NSButton的标题设置为±,现在我正在尝试获取此按钮的标题并将其转换回此“\ U00B1”;

例如

unichar theChar = [theButton.title characterAtIndex:0];
//now how would I change the above unichar to an string like @"\\u03b2"

1 个答案:

答案 0 :(得分:2)

一种解决方案是:

unichar theChar = ... 
NSString *escapeCode = [NSString stringWithFormat:@"\\\\u%04x", theChar];

注意你需要四个反斜杠才能在结果字符串中得到两个。