字符串中的 Unicode 字符 - iphone
我正在开发一个数学应用程序,需要将指数输出到屏幕上。
我发现这段代码可以工作:
NSLog(@"x\u2070 x\u00B9 x\u00B2 x\u00B3 x\u2074 x\u2075 x\u2076 x\u2077 x\u2078 x\u2079");
它显示:x⁰ x1 x2 x3 x⁴ x⁵ x⁶ x⁷ x⁸ x⁹
这也可以工作:
NSString *testString = @"8.33x10\u00B3";
NSLog(@"test string: %@", testString);
它显示:测试字符串:8.33x10³
即使将其设置为标签,也会在 iPhone 屏幕上正确显示:
NSString *testString = @"8.33x10\u00B3";
Answer1Label.text = testString;
但是,当我从 .plist 中提取“8.33x10\u00B3”的字符串并将其显示在屏幕上时,它只显示为“8.33x10\u00B3”而不是 8.33x10³
是否需要在前面添加一个额外的字符\u00B3 让它识别?
感谢您的帮助!
I am working on a math app and need to output exponents to the screen.
I've found that this code will work:
NSLog(@"x\u2070 x\u00B9 x\u00B2 x\u00B3 x\u2074 x\u2075 x\u2076 x\u2077 x\u2078 x\u2079");
it displays: x⁰ x¹ x² x³ x⁴ x⁵ x⁶ x⁷ x⁸ x⁹
This also works:
NSString *testString = @"8.33x10\u00B3";
NSLog(@"test string: %@", testString);
it displays: test string: 8.33x10³
Even setting it to a label displays correctly on the iPhone screen:
NSString *testString = @"8.33x10\u00B3";
Answer1Label.text = testString;
However, when I pull the string from a .plist that says "8.33x10\u00B3" and display it on the screen, it just shows up as "8.33x10\u00B3" instead of 8.33x10³
Is there an additional character I need to put in front of the \u00B3 to get it to recognize?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
\uXXXX 在编译时转换为 unicode,因此您不会期望通过读取 .plist 来神奇地转换它。
尝试在 Xcode 中以“文本模式”打开 plist 文件(右键单击您的 plist 文件,打开为 -> 计划文本文件),然后使用以下形式的文本编辑所需的字符串以包含特殊字符:
而不是通常您在代码中使用的
\u2070
。然后,如果您保存 plist,关闭它,然后双击再次打开它,您将看到通常的 plist 编辑器视图,并且它将包含您的特殊字符。或者,考虑使用 OS X 的字符查看器(也称为字符调色板)将文本直接输入到 Xcode 中的 plist 编辑器中。 更多信息。
The \uXXXX is converted into unicode at compile time, so you wouldn't expect that to be magically converted by reading a .plist.
Try opening the the plist file in Xcode in "text mode" (right click your plist file, Open As -> Plan Text File), then edit the desired string to contain the special characters by using text of the form:
rather than the usual
\u2070
you've been using in-code. Then if you save your plist, close it, and open it again by double clicking, you'll see the usual plist editor view and it will contain your special characters.Alternatively, consider using OS X's character viewer (aka character palette) to input the text directly into the plist editor in Xcode. More info.