Decode HTML escaped characters back to a regular string in C #

My question is simple. I searched a bit on the Internet, but couldn't find a quick way to unescape HTML text in a string.

For example:
"&lt; &gt; &amp;"should be returned in "<> &" as a string.

Is there a quick way, or do I need to write my own unescaper?

+5
source share
3 answers

use System.Web.HttpUtility.HtmlDecodeorSystem.Net.WebUtility.HtmlDecode

var decoded = HttpUtility.HtmlDecode("&lt; &gt; &amp;");
+10
source

If you are using .NET 4.5, you can use the method HttpUtility.HtmlDecode.

+1
source
HttpUtility.UrlDecode("Your escaped String", System.Text.Encoding.Default);
+1
source

All Articles