2012-05-24 66 views
7

我有一个字符串,例如像这样:转换HTML代码以纯文本

Col´gio 

我怎样才能将其转换为:

Colégio 

无需做所有的HTML一个替代代码

+1

见http://stackoverflow.com/questions/1144535/c-sharp-htmlencode-from-class-library或http:/ /stackoverflow.com/questions/122641/how-can-i-decode-html-characters-in-c。还有很多其他的实例 - 你需要Html解码字符串。 – dash

回答

12
System.Web.HttpUtility.HtmlDecode("Col´gio"); 
2
SecurityElement securityElement = System.Security.SecurityElement.FromString("<test>H&amp;M</test>"); 
string unescapedText = securityElement.Text; 
Console.WriteLine(unescapedText); // Result: H&M 
6

刚刚完成日期:

如果您使用的是.NET 4.0+你也可以使用WebUtility.HtmlDecode