Reputation: 35
I have NSDictionary whom contents I read from a .plist which is encoded in utf-8.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ABACİ</key>
<array>
<string>ABALİ</string>
<string>APACİ</string>
<string>ARAÇİ</string>
</array>
and so on
Anyway, the problem is when I NSLog the contents on this dictionary to the console, I get results like
"K\U00d6PEK"
this is logged version of another entry which doesn't contain regular latin english characters. The characters I try to use are in UTF-8 encoding.
However, when I read the contents of an array from a text file
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"words_tr" ofType:@"txt"];
NSString *contentString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
_wordStack = [[NSMutableArray alloc]initWithArray:[contentString componentsSeparatedByString:@","]];
this works perfectly. I want to do the same for reading from the property list as well. How can I get results encoded in UTF-8 for the NSDictionary?
Upvotes: 2
Views: 5360
Reputation: 4667
+(NSString*)utf8toNString:(NSString*)str{
NSString* strT= [str stringByReplacingOccurrencesOfString:@"\\U" withString:@"\\u"];
//NSString *strT = [strTemp mutableCopy];
CFStringRef transform = CFSTR("Any-Hex/Java");
CFStringTransform((__bridge CFMutableStringRef)strT, NULL, transform, YES);
return strT;
}
Upvotes: 1
Reputation: 24256
Did you try to NSLog by this?
NSLog(@"%@", [NSString stringWithCString:contentString encoding:NSUTF8StringEncoding]);
Upvotes: 1