在C#转换HTML实体Unicode字符 [英] Converting HTML entities to Unicode Characters in C#

查看:606
本文介绍了在C#转换HTML实体Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现为Python和JavaScript类似的问题和答案,但不能用于C#或其他任何WinRT的兼容的语言。

I found similar questions and answers for Python and Javascript, but not for C# or any other WinRT compatible language.

我想我需要它,是因为我在Windows 8商店应用中显示文本,我从网站上获取。例如。 &放大器; eacute; 应成为电子

The reason I think I need it, is because I'm displaying text I get from websites in a Windows 8 store app. E.g. é should become é.

或有没有更好的办法?我不显示网站或RSS源,但只是一个网站列表和它们的标题。

Or is there a better way? I'm not displaying websites or rss feeds, but just a list of websites and their titles.

推荐答案

我推荐使用<强> System.Net.WebUtility.HtmlDecode 不会 HttpUtility.HtmlDecode

这是由于这样的事实,即的System.Web 参考文献没有Winforms中/ WPF /控制台应用存在以及你可以使用这个类(已添加在所有这些项目的引用)完全相同的结果。

This is due to the fact that the System.Web reference does not exist in Winforms/WPF/Console applications and you can get the exact same result using this class (which is already added as a reference in all those projects).

用法:

string s =  System.Net.WebUtility.HtmlDecode("&eacute;"); // Returns é

这篇关于在C#转换HTML实体Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆