ios - How to convert unicode hex number variable to character in NSString? -
now have range of unicode numbers, want show them in uilabel, can show them if hardcode them, that's slow, want substitute them variable, , change variable , relevant character. example, know unicode u+095f, want show range of u+095f u+096f in uilabel, can hardcode like
nsstring *str = [nsstring stringwithformat:@"\u095f"];
but want
nsinteger hex = 0x095f;
[nsstring stringwithformat:@"\u%ld", (long)hex];
i can change hex automatically,just using @"%ld", (long)hex
, know how implement that?
you can initialize string buffer of bytes of hex (you provide pointer). point is, , important thing notice provide character encoding applied. should notice byte order.
here's example:
uint32 hex = 0x095f; nsstring *unicodestring = [[nsstring alloc] initwithbytes:&hex length:sizeof(hex) encoding:nsutf32littleendianstringencoding];
note solutions using %c
format fine long use them 16-bit unicode characters; 32-bit unicode characters emojis (for example: 0x1f601, 0x1f41a) not work using simple formatting.
Comments
Post a Comment