5

我尝试使用 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 编码文件。

有人有想法吗?

4

1 回答 1

5

您的文件是 Windows-1252 编码的。非 Unicode 的文件中没有数据来指示文件是如何编码的。在这种情况下,ANSI 只是意味着不是 Unicode。如果您在哪里将其编码为俄语/Windows-1251 并在 Notepad++ 中打开它,Notepad++ 也会将其显示为 ANSI。

有关详细信息,请参阅Unicode、UTF、ASCII、ANSI 格式差异

于 2012-11-06T17:59:07.053 回答