Goal C: How to get the Ascii Integer value of the first letter of NSString?

Goal C: How to get the Ascii Integer value of the first letter of NSString?

+3
source share
3 answers
if ([aString length] > 0) {
    unichar firstCharacter = [aString characterAtIndex: 0];
    // ...
}

It's all. unicharis an alias unsigned shortand is also an integer type. However, there is no guarantee that a character is part of ASCII, as it is NSStringbased on Unicode.

+7
source
unichar ch = [myString characterAtIndex: 0]

, , unichar unicode, typedef . NSString ASCII, ASCII, ASCII. , .

+3

If you really need to do this, include the first character of the string in ASCII encoded NSData and then read it.

There's some help in the String Programming Guide .

0
source

Source: https://habr.com/ru/post/1779847/


All Articles