我尝试使用 StreamWriter 在 Windows-1252 中对字符串进行编码。输入字符串 (dataString) 以 UTF8 编码。
StreamWriter sw = new StreamWriter(@"C:\Temp\data.txt", true, Encoding.GetEncoding(1252));
sw.Write(dataString);
sw.Close();
当我在 Notepad++ 中打开文件时,我得到一个 ANSI 文件。我需要一个 Windows-1252 编码文件。
有人有想法吗?
最佳答案
您的文件采用 Windows-1252 编码。非 Unicode 文件中没有数据表明文件是如何编码的。在这种情况下,ANSI 就意味着不是 Unicode。如果您在哪里将其编码为 Russian/Windows-1251 并在 Notepad++ 中打开它,Notepad++ 也会将其显示为 ANSI。
关于c# - StreamWriter 中的 Windows-1252 编码返回 ANSI 编码文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13255733/