?I’m building a NSMutableArray of NSStrings from a list and some of the letters are accented (Turkish). I have been able to encode into a NSString and NSLog the results. But when I add that NSString to my NSMutableArray the encoding is incorrect.
This works:
NSString* temp = [[NSString alloc] init];
char *str = "üç";
temp = [NSString stringWithUTF8String:"üç"];
NSLog(@"str: %@",temp);
Logged output:
2012-06-09 09:09:18.398 Fluent[1821:f803] str: üç
When I try to add it to my NSMutableArray like this:
ones = [NSArray arrayWithObjects:@"",@"bir",@"iki",temp,@"dört",@"beş",@"altı",@"yedi",@"sekiz",@"dokuz",nil];
NSLog(@"ones: %@",ones);
It loses the encoding:
2012-06-09 09:09:18.399 Fluent[1821:f803] ones: (
"",
bir,
iki,
"\U00fc\U00e7",
"d\U00f6rt",
"be\U015f",
"alt\U0131",
yedi,
sekiz,
dokuz)
Any ideas on how to do this? The posts I have read around this area seem to be focused on transfer over HTTP.
I’d like a simpler approach such as to encode a C-string if this is necessary and then unstring by spaces into the array.
Your strings aren’t incorrectly encoded. What you see is an artifact of writing a complete array to the log. In this case, the array is first converted to the property list format and then written to the log.
If you create a loop and write each element separately to the log, you’ll see that everything is ok: