开发者

How do I get the int ASCII value of a character in Cocoa?

How do I get the ASCII value as an int of a character in Cocoa? I found an answer for doing this in python, but I need to know how to do this in Cocoa. ( I am still a noob in Cocoa).

Python method:

use function ord() like this:

>>> o开发者_Go百科rd('a')  
97

and also chr() for the other way around:

>>> chr(97)  
'a'

how do I do this in Cocoa?


Character constants are already integers:

int aVal = 'a'; // a is 97, in the very likely event you're using ASCII or UTF-8.

This really doesn't have anything to do with Cocoa, which is a library. It's part of C, so it's not specific to Objective-C either.


It has nothing to do with Cocoa, it depends on the language, simply in C or C++ make a cast to int to the char :)

C++:

#include <iostream>

int main()
{
int number;
char foo = 'a';
number = (int)foo;

std::cout << number << std::endl;
return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜