Reputation: 5200
I know how to convert a 'C' style string into a NSString
, but is there an elegant (or even just easy!) way of converting a single 'C' char into a single character NSString
?
I.e. 'Z' -> @"Z"
Short of creating a char *string and setting string[0] = myChar
and then using
[NSString stringWithUTF8String:string]
I can't see a better way.
Upvotes: 0
Views: 558
Reputation: 540105
Alternative solution (just for fun!), using a C99 "Compound Literal" with a Objective-C "Boxed Expression":
char myChar = 'A';
NSString *string = @((char[]){myChar, 0});
Upvotes: 3
Reputation: 1312
try using
char myChar = 'r';
NSString* string = [NSString stringWithFormat:@"%c" , myChar];
Upvotes: 3