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

1
  • The Problem just occures inside the console, i printed out the String to my TextView and everything works fine. If i should delete the post maybe somebody should post a comment otherwise it could be a good help for somebody with the same problem... Commented Jun 6, 2012 at 21:55

1 Answer 1

1

First, get rid of all the extra calls to UTF8String. There's no reason to convert back and forth.

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);
    }
}

If you still see trouble, then verify that LevelText.plist is UTF8 encoded, but I suspect the above will fix the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.