iPhone - Convert NSString encoding from WindowsCP1251 to UTF8
how can I have this conversion from NSWindowsCP1251StringEncoding
to UTF-8
?
I had several attempts but no one worked as it should. My last try was:
NSData *dt = [mystr dataUsingEncoding:NSUTF8StringEncoding];
NSString *str = [NSString alloc] initWithData:dt encoding:NSWindowsCP1251StringEncoding];
The result of str
is unreadable.开发者_StackOverflow Did anyone encounter anything similar?
I think you were so close:
// Convert it back to CP1251
NSData *dt = [mystr dataUsingEncoding:NSWindowsCP1251StringEncoding];
// Now load it as UTF8
NSString *str = [NSString alloc] initWithData:dt encoding:NSUTF8StringEncoding];
精彩评论