Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Ascii Integer value of the first letter of a NSString in Objective-C?

In Objective-C, how to get the Ascii Integer value of the first letter of a NSString?

like image 290
Unreality Avatar asked Oct 30 '25 02:10

Unreality


1 Answers

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.

like image 191
Jonathan Grynspan Avatar answered Nov 02 '25 22:11

Jonathan Grynspan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!