How to read and write an NSString with UTF8N?
How to read and write an NSString with UTF8N? I use this to load a UTF-8 file and it see开发者_开发知识库ms to work with UTF-8N.
NSString *string = [NSString stringWithContentsOfFile:destPath encoding:NSUTF8StringEncoding error:&error];
The problem is when I save the file with
[string writeToFile:tempFile atomically:YES encoding:NSUTF8StringEncoding error:&error];
the file is not readable in a normal text editor on the computer. I can still read the file as a UTF-8 file though.
What am I missing?
A bunch of guess and check found NSShiftJISStringEncoding
did the trick.
Try to write the string to file without providing any encoding
[string writeToFile:tempFile atomically:YES];
精彩评论