将HTML代码转换为纯文本

时间:2021-03-03 00:25:29

I've a string for example like this:

我有一个字符串,例如:

Col´gio

How can I convert it to:

我怎样才能将其转换为:

Colégio

Without having to do a replace for all the html codes

无需替换所有的html代码

3 个解决方案

#1


14  

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

#2


8  

Just for completion:

刚完成:

If you are using .NET 4.0+ you can also use WebUtility.HtmlDecode

如果您使用的是.NET 4.0+,则还可以使用WebUtility.HtmlDecode

#3


2  

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

#1


14  

System.Web.HttpUtility.HtmlDecode("Col&acute;gio");

#2


8  

Just for completion:

刚完成:

If you are using .NET 4.0+ you can also use WebUtility.HtmlDecode

如果您使用的是.NET 4.0+,则还可以使用WebUtility.HtmlDecode

#3


2  

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