开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜