c# - ansi 到 unicode 转换

标签 c# encoding typography

在解析某些文档时,我得到字符代码 146,这实际上是一个 ANSI 数字。将字符写入文本文件时,不显示任何内容。如果我们将字符写成 Unicode 数字 - 8217,则字符显示正常。

谁能给我一些建议,告诉我如何在 C# 中将 ANSI 数字 146 转换为 Unicode 8217。

引用:http://www.alanwood.net/demos/ansi.html

谢谢

最佳答案

“ANSI”确实用词不当——有许多编码通常被称为“ANSI”。但是,如果您确定需要代码页 1252,则可以使用:

Encoding encoding = Encoding.GetEncoding(1252);
using (TextReader reader = File.OpenText(filename, encoding))
{
    // Read text and use it
}

Encoding encoding = Encoding.GetEncoding(1252);
string text = File.ReadAllText(filename, encoding);

那是为了一个文件 - 写一个文件是同样的想法。基本上,当您从二进制(例如文件内容)转换为文本时,请使用适当的 Encoding对象。

关于c# - ansi 到 unicode 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6184177/

相关文章:

python - 使用 python 请求 POST 编码

html - FF 中未加载 Typography.com 字体

css - 是否可以添加 Myriad pro 字体,就像离线 Web 应用程序的自定义字体一样

c# - wpf 应用程序中的自定义组合框

c# - 如何找出哪个 IIS Express 实例正在使用端口?

c# - NUnit 的 ExpectedExceptionAttribute 是测试是否引发异常的唯一方法吗?

machine-learning - 如何将分类数据映射到 python pandas dataframe 中的category_encoders.OrdinalEncoder

c# - Asp.Net 查询字符串

css - 如何在 Webkit 浏览器(Chrome、Safari)的段落首行使用全大写字母

c# - 未知类型的类型转换节点