How to append unicode
ranging U+0000
to U+0099
To NSString in iOS. I have used the following link for reference http://en.wikipedia.org/wiki/List_of_Unicode_characters

- 5,262
- 4
- 38
- 68
-
For a string literal? What have you tried? http://stackoverflow.com/questions/5690172/xcode-utf-8-literals a NUL character is not supported within a string (it indicates the terminator of the string). If, however you're actually trying to construct binary data, then a string is not the correct data type for that – Anya Shenanigans May 23 '13 at 07:02
-
What do you mean by "add" them? Append them to an existing string? Or put them into a literal NSString? – borrrden May 23 '13 at 07:02
2 Answers
Try to use this one....
NSString
uses UTF-16 to store codepoints internally, so those in the range you're looking for (U+1F300 to U+1F6FF) will be stored as a surrogate pair (four bytes). Despite its name, characterAtIndex: (and unichar) doesn't know about codepoints and will give you the two bytes that it sees at the index you give it (the 55357 you're seeing is the lead surrogate of the codepoint in UTF-16).
To examine the raw codepoints, you'll want to convert the string/characters into UTF-32 (which encodes them directly). To do this, you have a few options:
1) Get all UTF-16 bytes that make up the codepoint, and use either this algorithm or CFStringGetLongCharacterForSurrogatePair to convert the surrogate pairs to UTF-32.
2) Use either dataUsingEncoding: or getBytes:maxLength:usedLength:encoding:options:range:remainingRange:
to convert the NSString to UTF-32, and interpret the raw bytes as a uint32_t.
3) Use a library like ICU.

- 17,485
- 5
- 50
- 66
I'm not sure this is 100% correct solution, but it works:
NSString *uniString = [NSString stringWithFormat:@"%C", (unichar)0x0021];
Where 0x0021
is your unicode char code.
You can test it with this loop:
for (unichar ch = 0x0000; ch <= 0x0099; ch++) {
NSString *uniString = [NSString stringWithFormat:@"%C", ch];
NSLog(@"%@", uniString);
}

- 7,604
- 2
- 25
- 50