What’s the easiest way to get the Unicode value from an NSString? For example,
NSString *str = "A";
NSString *hex;
Now, I want to set the value of hex to the Unicode value of str (i.e. 0041)… How would I go about doing that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
unichartype is defined to be a 16-bit unicode value (eg, as indirectly documented in the description of the %C specifier), and you can get aunicharfrom a given position in anNSStringusingcharacterAtIndex:, or usegetCharacters:range:if you want to fill a C array of unichars from theNSStringmore quickly than by querying them one by one.NSUTF32StringEncodingis also a valid string encoding, as are a couple of endian-specific variants, in case you want to be absolutely future proof. You’d get a C array of those using the much more longwindedgetBytes:maxLength:usedLength:encoding:options:range:remainingRange:.EDIT: so, e.g.