Created
May 22, 2013 20:53
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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