解码所有HTML实体 [英] Decoding all HTML Entities

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

问题描述

我正在寻找一些功能,将取消code量好HTML实体。

I'm looking for some function that will decode a good amount of HTML entities.

原因是我工作的一些code采取HTML内容,并把它变成纯文本,我有这个问题是很多实体做的的被转换使用 HttpUtility.HtmlDe code

Reason is I am working on some code to take HTML content and turning it into plain text, the issue that I have is a lot of entities do not get converted using HttpUtility.HtmlDecode.

我担心实体的一些例子是&放大器; NBSP;,&放大器;放大器;,&安培;复制;

Some examples of entities I'm concerned about are  , &, ©.

编辑:这是对的 .NET 3.5

推荐答案

那么,也许你需要在 HttpUtility .HtmlDe code?
它应该工作,你只需要添加的System.Web引用。
至少,这是.Net框架和LT的方式; 4。

Then maybe you will need the HttpUtility.HtmlDecode?. It should work, you just need to add a reference to System.Web. At least this was the way in .Net Framework < 4.

例如下面的code:

MessageBox.Show(HttpUtility.HtmlDecode("&amp;&copy;"));

任职和产量预期(符号和版权符号)。
你确定这个问题是内HtmlDe code,而不是别的?

Worked and the output was as expected (ampersand and copyright symbol). Are you sure the problem is within HtmlDecode and not something else?

更新:能胜任此项工作的另一类,WebUtility(再次HtmlDe code法)排在净的新版本。然而,似乎有一些问题吧。请参阅<一个href=\"http://stackoverflow.com/questions/17352981/webutility-htmlde$c$c-vs-httputilty-htmlde$c$c\">HttpUtility与WebUtility 问题。

UPDATE: Another class capable of doing the job, WebUtility (again HtmlDecode method) came in the newer versions of .Net. However, there seem to be some problems with it. See the HttpUtility vs. WebUtility question.

这篇关于解码所有HTML实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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