Converting escaped UTF8 characters back to their original form

It sounds like the string in the plist contains the characters “\u0161” rather than the Unicode character number 0x161. So you need to decode the \u escapes in the string you’ve extracted from the plist. NSString can do that for you using NSNonLossyASCIIStringEncoding:

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
    @autoreleasepool {
        NSString *name2escaped = @"Nu\\u0161a Florjan\\u010di\\u010d";
        NSString *name2 = [NSString
            stringWithCString:[name2escaped cStringUsingEncoding:NSUTF8StringEncoding]
            encoding:NSNonLossyASCIIStringEncoding];
        NSLog(@"name2 = %@", name2);
    }
    return 0;
}

Leave a Comment