okami
okami

Reputation: 2153

Get a string with ascii code objective-c

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?

Upvotes: 0

Views: 4089

Answers (2)

zoul
zoul

Reputation: 104065

This could also work:

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

Didn’t test it.

Upvotes: 7

Chuck
Chuck

Reputation: 237010

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];

Upvotes: 4

Related Questions