c# 编码转换?
我有一个看起来像这样的字符串:
À l'intérieur
但它需要是:
À l'intérieur
我尝试更改转换。我知道它被读取为 ASCII 编码。所以我尝试使用代码:
ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
Byte[] BytesMessage = ASCII.GetBytes(Title);
Title = Encoding.UTF8.GetString(BytesMessage);
我尝试在不同的编码之间切换,但没有多大帮助。 有办法解决这个问题吗?
谢谢!
I have a string which looks like:
À l'intérieur
But it needs to be:
À l'intérieur
I tried changing the conversion. I know it's read as ASCII encoding. So I tried using the code:
ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
Byte[] BytesMessage = ASCII.GetBytes(Title);
Title = Encoding.UTF8.GetString(BytesMessage);
I tried switching between the different encodings but it didn't help much.
Is there a way to fix this?
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这实际上不是一种字符编码(例如 ASCII 或 UTF-8),而是一种为任意字符定义转义序列的高级协议 - 在本例中是 SGML,它充当 HTML 的基础和XML。
您可以使用 HtmlDecode 方法HttpUtility 类对其进行解码:
但是,此类驻留在 System.Web 命名空间中,因此它可能无法立即在非 ASP.NET 项目中可用。
Well, this is actually not a character encoding (such as ASCII or UTF-8) but rather a higher-level protocol defining escape sequences for arbitrary characters—in this case SGML which serves as the basis for HTML and XML.
You can use the HtmlDecode method of the HttpUtility class to decode it:
However, this class resides in the System.Web namespace so it's probably not immediately available in a non-ASP.NET project.
要像这样对 HTML 编码的字符串进行转码,请使用 System.Web.HttpUtility.HtmlDecode(Title)。如果这不是 Web 应用程序,您需要引用
System.Web
。To transcode HTML encoded strings like this use
System.Web.HttpUtility.HtmlDecode(Title)
. You'll need to referenceSystem.Web
if this is not a Web application.