[英]iOS special characters, strange issue
I've got a very strange issue. 我有一个非常奇怪的问题。 I started an iOS App about three years ago (iOS-SDK 3.0), and since then went through the SDKs 4.0 and 5.0. 我大约三年前开始使用iOS应用程序(iOS-SDK 3.0),从那时起就开始使用SDK 4.0和5.0。 Since 5.0 (or maybe 5.1) I suddenly started having problems with German special chars (ä ö ü ß). 从5.0(或5.1)开始,我突然开始遇到德国特殊字符(äöüß)的问题。
Now I can't even initialize an NSString with special chars, this line: 现在我甚至无法使用特殊字符初始化NSString,这一行:
NSString *str = @"abcäxyz";
gives the following warning: 发出以下警告:
Input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 由于输入字节不属于输入代码集UTF-8,输入转换停止
And this one: 还有这个:
NSLog(@"%@", strTemp);
gives: 得到:
abc ABC
So it's stopping at the first special char. 所以它停在第一个特殊的char。 In other projects everything is fine. 在其他项目中一切都很好。 I can work with special chars without any problems. 我可以毫无问题地使用特殊字符。
Is it a configuration problem? 这是配置问题吗?
EDIT: Obviously it is a problem with the file encoding. 编辑:显然这是文件编码的问题。
file -I myFile 文件-I myFile
is giving: 给予:
text/x-c++; 文本/ X-C ++; charset=unknown-8bit 字符集=未知-8位
Trying to convert it with iconv gives me: 试图用iconv转换它给了我:
conversion from unknown-8bit unsupported 转换自未知-8位不受支持
What happens when you use the UTF-8 codes to initialize the string? 使用UTF-8代码初始化字符串时会发生什么? Like so: 像这样:
NSString *s = [NSString stringWithFormat:@"%C", 0xc39f]; // should be ß
As far as I know you should also be able to do this, but haven't tested it: 据我所知,你也应该能够这样做,但还没有测试过:
NSString *s = [NSString stringWithUTF8String:"0xc39f"];
Try those and see what happens. 试试这些,看看会发生什么。 There's a number of sites around that keep UTF-8 code tables for special characters, eg this one . 周围有许多站点可以保留特殊字符的UTF-8代码表,例如这个 。
As long as your file is encoded UTF-8, @"abcäxyz"
should be fine, but the explicit form of embedding a literal unicode characters is \\u????. 只要您的文件编码为UTF-8, @"abcäxyz"
应该没问题,但嵌入文字unicode字符的显式形式是\\ u ????。
- (void)testGermanChar
{
NSString *expected = @"abc\u00E4xyz";
NSString *actual = @"abcäxyz";
STAssertEqualObjects(expected, actual, @"the two strings should be equivalent");
}
SOLVED: Changed the file encoding in Xcode: Click on the file you want to change the encoding of, then open the right panel (whats the name of this pane actually? any idea?) to edit the properties. 已解决:更改了Xcode中的文件编码:单击要更改其编码的文件,然后打开右侧面板(实际上这个窗格的名称是什么?任何想法?)来编辑属性。 There you see "Text Encoding" under "Text Settings". 在那里,您会看到“文本设置”下的“文本编码”。 That is all. 就这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.