Unicode Character from Code in String (Obj-C)

后端 未结 1 1391
感动是毒
感动是毒 2020-12-19 23:39

I have a unicode hex value in an NSString - how do I output the character; here\'s what I have:

NSLog(@\"\\U0001D000\");

NSMutableString *hexString = [[NSMu         


        
相关标签:
1条回答
  • 2020-12-20 00:13

    If your character requires a surrogate pair (U+10000 to U+10FFFF), use CFStringGetSurrogatePairForLongCharacter to convert the Unicode code point into a UTF-16 surrogate pair, and then -initWithCharacters:length: to convert it into an NSString. For example:

    UniChar c[2];
    CFStringGetSurrogatePairForLongCharacter(0x1D000, c);
    NSString *s = [[NSString alloc] initWithCharacters:c length:2];
    

    For other characters (CFStringGetSurrogatePairForLongCharacter returns FALSE), you can skip the conversion and go straight to -initWithCharacters:length:.

    0 讨论(0)
提交回复
热议问题