开发者

Get a string with ascii code objective-c

开发者 https://www.devze.com 2022-12-29 16:47 出处:网络
I have a ascii code, for the letter \'a\', and I want to get a st开发者_StackOverflow中文版ring by its ascii code, is it possible with NSString?This could also work:

I have a ascii code, for the letter 'a', and I want to get a st开发者_StackOverflow中文版ring by its ascii code, is it possible with NSString?


This could also work:

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

Didn’t test it.


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

精彩评论

暂无评论...
验证码 换一张
取 消