Decode HTML escaped characters back to normal string in C#
16,061
Solution 1
use System.Web.HttpUtility.HtmlDecode
or System.Net.WebUtility.HtmlDecode
var decoded = HttpUtility.HtmlDecode("< > &");
Solution 2
If you're using .NET 4.5 then you can use the HttpUtility.HtmlDecode
method.
Solution 3
HttpUtility.UrlDecode("Your escaped String", System.Text.Encoding.Default);
Author by
Mario Stoilov
Updated on June 26, 2022Comments
-
Mario Stoilov almost 2 years
My question is simple. I searched a little online, but could not find a quick way to unescape HTML text in a string.
For example:
"< > &"
should be returned to "< > &" as a string.Is there a quick way, or do I have to write my own unescaper?
-
Mario Stoilov about 11 yearsIs there a difference between these two?
-
P-L over 10 yearsHttpUtility.HtmlDecode is available since .NET 1.1. msdn.microsoft.com/en-us/library/…
-
Hitesh over 6 yearsit does not unescape jav
-
Hitesh over 6 years@jazzcat, did you find the solution?