Skip to content

Instantly share code, notes, and snippets.

@mluton
Created December 14, 2012 06:48
Show Gist options
  • Save mluton/4283232 to your computer and use it in GitHub Desktop.
Save mluton/4283232 to your computer and use it in GitHub Desktop.
Create string from unicode.
// Guaranteed to get the characters in the 'illegal' ranges the compiler will complain about.
NSMutableAttributedString *attrStr = [NSMutableAttributedString attributedStringWithString:[NSString stringWithFormat:@"%C", (unsigned short)0xe007]];
// Same thing but use a string as the original source of the unicode instead of a literal.
unsigned int intValue;
NSScanner* scanner = [NSScanner scannerWithString:@"e007"];
[scanner scanHexInt:&intValue];
NSMutableAttributedString *attrStr = [NSMutableAttributedString attributedStringWithString:[NSString stringWithFormat:@"%C", (unsigned short)intValue]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment