How can I make unicode characters from integers?
cocoa, nsstring, objective-c, string, unicode
Solution
You should use %C to insert a unicode character:
NSMutableArray *uniArray = [[NSMutableArray alloc] initWithCapacity:0];
int i;
for (i = 32; i < 300; i++) {
NSString *uniString = [NSString stringWithFormat:@"%C", i];
[uniArray addObject:uniString];
}
Another (better?) way is using stringWithCharacters:
NSMutableArray *uniArray = [[NSMutableArray alloc] initWithCapacity:0];
int i;
for (i = 32; i < 300; i++) {
NSString *uniString = [NSString stringWithCharacters:(unichar *)&i length:1];
[uniArray addObject:uniString];
}
Problem
I want to make an array of Unicode characters, but I don't know how to convert integers into a Unicode representation. Here's the code I have so far ``` NSMutableArray *uniArray = [[NSMutableArray alloc] initWithCapacity:0]; int i; for (i = 32; i < 300; i++) { NSString *uniString = [NSString stringWithFormat:@"\u%04X", i]; [uniArray addObject:uniString]; } ``` Which gives me an error "incomplete universal character name \u" Is there a better way to build an array of Unicode symbols? Thanks.