Reputation: 1791
I was wondering if anyone has the following php function equivalents in Objective-C for iPhone development:
Many thanks!
Upvotes: 37
Views: 50498
Reputation: 6077
This is how you can work with ASCII values and NSString
. Note that since NSString
is working with unichars, there could be unexpected results for a non ASCII string.
// 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
Upvotes: 119
Reputation: 37494
//char to int ASCII-code
char c = 'a';
int ascii_code = (int)c;
//int to char
int i = 65; // A
c = (char)i;
Upvotes: 12