简体   繁体   中英

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. Since 5.0 (or maybe 5.1) I suddenly started having problems with German special chars (ä ö ü ß).

Now I can't even initialize an NSString with special chars, this line:

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

And this one:

NSLog(@"%@", strTemp);

gives:

abc

So it's stopping at the first special 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


is giving:

text/x-c++; charset=unknown-8bit

Trying to convert it with iconv gives me:

conversion from unknown-8bit unsupported

What happens when you use the UTF-8 codes to initialize the string? 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 .

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????.

- (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. There you see "Text Encoding" under "Text Settings". That is all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM