c# - StreamWriter 中的 Windows-1252 编码返回 ANSI 编码文件

标签 c# string c#-4.0

我尝试使用 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。

参见 Unicode, UTF, ASCII, ANSI format differences了解更多信息。

关于c# - StreamWriter 中的 Windows-1252 编码返回 ANSI 编码文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13255733/

相关文章:

c++ - 为什么cout会阻止后续代码在这里运行呢?

c - 动态分配字符串数组

R:查看两个简单字符串的唯一元素时的奇怪结果

authentication - asp.net mvc 3 : Page. User.IsInRole ("xy") 返回 null

asp.net-mvc - 当 string[] 中不存在列名时,创建列名 List<string> 的最佳方法是什么?

c# - 如何在 WPF 应用程序中使用 App.config 进行 log4net 配置

c# - LINQ Lambda 左连接与内连接

c#-4.0 - 使用动态关键字调用子类方法

c# - 使用简单注入(inject)器注册 IAuthenticationManager

C#:如何构造这个要被覆盖的方法