将HTML代码转换为纯文本

10

我有一个字符串,比如:

Col´gio

我该如何将它转换为:

Colégio

无需对所有HTML代码进行替换


1
请参考以下链接:https://dev59.com/PXM_5IYBdhLWcg3w-4dg 或 https://dev59.com/kHVD5IYBdhLWcg3wAGiD。还有很多其他类似的情况 - 您需要对字符串进行Html解码。 - dash
3个回答

17
System.Web.HttpUtility.HtmlDecode("Col´gio");

9

仅供完整性说明:

如果您正在使用.NET 4.0+,您也可以使用WebUtility.HtmlDecode。


2
SecurityElement securityElement = System.Security.SecurityElement.FromString("<test>H&amp;M</test>");
string unescapedText = securityElement.Text;
Console.WriteLine(unescapedText); // Result: H&M

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接