Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created May 22, 2013 20:53
Show Gist options
  • Save chrisallick/5630817 to your computer and use it in GitHub Desktop.
Save chrisallick/5630817 to your computer and use it in GitHub Desktop.
Wanna convert hex values of emojis into NSStrings so you can render them to the screen? Hahhahaha... YES!
-(NSString *)hexToString:(NSString *)hex {
NSScanner *scan = [[NSScanner alloc] initWithString:hex];
unsigned int val;
[scan scanHexInt:&val];
char cc[4];
cc[3] = (val >> 0) & 0xFF;
cc[2] = (val >> 8) & 0xFF;
cc[1] = (val >> 16) & 0xFF;
cc[0] = (val >> 24) & 0xFF;
NSString *s = [[NSString alloc]
initWithBytes:cc
length:4
encoding:NSUTF32StringEncoding];
return s;
}
// example usage
// controller.body = [NSString stringWithFormat:@"emojis => %@%@", [self hexToString:@"1F449"], [self hexToString:@"1F448"]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment