0

i have created a plist with strings. Inside the strings i have umlaute, and can't encode them to be shown correctly. my code looks like this:

NSString *myFile = [[NSBundle mainBundle] pathForResource:@"LevelText" ofType:@"plist"];

    strings = [[NSDictionary alloc]  initWithContentsOfFile:myFile ];
    stringkeys = [strings allKeys];
    NSEnumerator *enumerator = [strings objectEnumerator];

    while (value = [enumerator nextObject]) {
        if(![value isEqualToString:@""]){
            NSString *right = [NSString stringWithCString:value.UTF8String encoding: NSUTF8StringEncoding];

            NSLog(@"Value: %s", right.UTF8String);
        }

    }

i get load the plist into a NSDictionary object and then enumerate through it. I also looked at another example on stackoverflow but it doesn't work like that. The Umlaut always is represented like that:

anhören

4

1 回答 1

1

首先,摆脱对UTF8String. 没有理由来回转换。

while (value = [enumerator nextObject]) {
    if([value length] > 0){ // A little safer approach that is a good habit to get into
        NSString *right = value;
        NSLog(@"Value: %@", right);
    }
}

如果您仍然看到问题,请验证它LevelText.plist是 UTF8 编码的,但我怀疑上述方法可以解决问题。

于 2012-06-06T21:50:09.260 回答