Obtaining Unicode Code Points
I have created an iPhone project available on my GitHub page that will return the Unicode code point value for a given character. The project also returns the ASCII value, when available, for the provided character. By having the code point for a character, you have more reference information. You’re more easily able to search for the character and reproduce it, and then test it against a required font to ensure that a glyph for that character exists in the font set. You will also know what the impact on encoding this character will be. By having the code point value, you don’t need to keep the actual character saved in a file and then load the file and copy and paste the character.
The workflow of my project is this:
- You see a character from a text or Web site or even a file you’ve opened on your device.
- You select the character and then copy it.
- You switch to my project and paste it into the “String” field.
The GitHub project link is https://github.com/ShawnLaAppleDev/UnicodeValueGrabber.
The code takes advantage of both the NSString class method initWithString and the format specifier %04x to return the Hexadecimal value of supplied character. Note that the format specifier is set up to have four placeholders that include leading zeros (see Listing 2.6).
Listing 2.6 Returning the Unicode Code Points
unichar ch = [unicodeString characterAtIndex:0]; NSString *unicodeHex = [[NSString stringWithFormat:@"U+%04x", ch] uppercaseString]; return unicodeHex;