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

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -