Skip to content

Instantly share code, notes, and snippets.

@jilouc
Created July 2, 2012 13:54
Show Gist options
  • Save jilouc/3033358 to your computer and use it in GitHub Desktop.
Save jilouc/3033358 to your computer and use it in GitHub Desktop.
NSString *s = @"L'asso du jour est g\\U00e9niale";
NSMutableString *result = [NSMutableString string];
NSScanner *scanner = [NSScanner scannerWithString:s];
[scanner setCharactersToBeSkipped:nil];
while (![scanner isAtEnd]) {
NSString *chunk;
[scanner scanUpToString:@"\\U" intoString:&chunk];
[result appendString:chunk];
if ([scanner scanString:@"\\U" intoString:nil]) {
NSUInteger value = 0;
NSRange range = NSMakeRange([scanner scanLocation], 4);
NSString *code = [s substringWithRange:range];
[[NSScanner scannerWithString:code] scanHexInt:&value];
[result appendFormat:@"%C", (unichar)value];
[scanner scanString:code intoString:nil];
}
}
label.text = result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment