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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With