Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将HTML代码转换为纯文本_C#_Asp.net_.net_String - Fatal编程技术网

C# 将HTML代码转换为纯文本

C# 将HTML代码转换为纯文本,c#,asp.net,.net,string,C#,Asp.net,.net,String,我有一个字符串,例如: Col´gio 如何将其转换为: Colégio 无需替换所有html代码SecurityElement SecurityElement=System.Security.SecurityElement.FromString(“H&M”); System.Web.HttpUtility.HtmlDecode("Col´gio"); 字符串unescapedText=securityElement.Text; Console.Wr

我有一个字符串,例如:

Col´gio
如何将其转换为:

Colégio
无需替换所有html代码

SecurityElement SecurityElement=System.Security.SecurityElement.FromString(“H&M”);
System.Web.HttpUtility.HtmlDecode("Col´gio");
字符串unescapedText=securityElement.Text; Console.WriteLine(unescapedText);//结果:H&M
仅用于完成:

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

请参阅或。还有很多其他的例子——你需要用Html解码字符串。
SecurityElement securityElement = System.Security.SecurityElement.FromString("<test>H&amp;M</test>");
string unescapedText = securityElement.Text;
Console.WriteLine(unescapedText); // Result: H&M