Decode String with Emoji characters such as \ud83d

I was able to find a solution and Edited it a bit. This un escapes the unicode characters perfectly and shows them properly. Shows the new lines too. Thanks @DanZimm for help.

- (NSString*) unescapeUnicodeString2:(NSString*)string
{
    NSString* esc1 = [string stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];
    NSString* esc2 = [esc1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
    NSString* quoted = [[@"\"" stringByAppendingString:esc2] stringByAppendingString:@"\""];
    NSData* data = [quoted dataUsingEncoding:NSUTF8StringEncoding];

    NSString* unesc = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:NULL error:NULL];
    assert([unesc isKindOfClass:[NSString class]]);
    return unesc;
}

Solution found here I had to edit it because one of the methods were deprecated.

Leave a Comment