In Objective-C, how to get the Ascii Integer value of the first letter of a NSString?
if ([aString length] > 0) {
unichar firstCharacter = [aString characterAtIndex: 0];
// ...
}
That's all. unichar
is an alias of unsigned short
and so is an integer type. However, there is no guarantee the character is part of ASCII, as NSString
is Unicode-based.