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
2010-05-06 19:50:13
+4
A:
This could also work:
NSString *foo = [NSString stringWithFormat:@"%c", 97];
Didn’t test it.
zoul
2010-05-06 19:58:28
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
2010-05-06 20:30:25