views:

241

answers:

2

I have a ascii code, for the letter 'a', and I want to get a string by its ascii code, is it possible with NSString?

+3  A: 

If you mean you have a byte that represents an ASCII-encoded character and you want to make a string out of it, NSString has an initializer just for that.

 char characterCodeInASCII = 97;
 NSString *stringWithAInIt = [[NSString alloc] initWithBytes:&characterCodeInASCII length:1 encoding:NSASCIIStringEncoding];
Chuck
+4  A: 

This could also work:

NSString *foo = [NSString stringWithFormat:@"%c", 97];

Didn’t test it.

zoul
In theory it's not completely reliable as it just assumes an ASCII-compatible encoding, but in practice I doubt this will be a problem.
Chuck