开发者

How to read and write an NSString with UTF8N?

开发者 https://www.devze.com 2023-01-16 00:35 出处:网络
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.

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

精彩评论

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