Jak przekonwertować wartość ASCII na znak w Objective-C?
Zastanawiałem się, czy ktoś ma następujące odpowiedniki funkcji php w Objective-C dla rozwoju iPhone ' a:
- ord () # Zwraca wartość ASCII pierwszego znaku łańcucha.
- chr () # Zwraca znak z podanej wartości ASCII.
Wielkie dzięki!
34
2 answers
Tak można pracować z wartościami ASCII i NSString
. Zauważ, że ponieważ NSString
działa z unichars, mogą pojawić się nieoczekiwane wyniki dla łańcucha innego niż ASCII.
// NSString to ASCII
NSString *string = @"A";
int asciiCode = [string characterAtIndex:0]; // 65
// ASCII to NSString
int asciiCode = 65;
NSString *string = [NSString stringWithFormat:@"%c", asciiCode]; // A
113
Author: alleus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-14 09:06:32
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-14 09:06:32
//char to int ASCII-code
char c = 'a';
int ascii_code = (int)c;
//int to char
int i = 65; // A
c = (char)i;
11
Author: luvieere,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-14 08:29:27
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-14 08:29:27