Mario Stoilov
Mario Stoilov

Reputation: 3447

Decode HTML escaped characters back to normal string in C#

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:
"&lt; &gt; &amp;" should be returned to "< > &" as a string.

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

Upvotes: 8

Views: 17581

Answers (3)

Usman Younas
Usman Younas

Reputation: 1379

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

Upvotes: 2

Rikki
Rikki

Reputation: 646

If you're using .NET 4.5 then you can use the HttpUtility.HtmlDecode method.

Upvotes: 1

I4V
I4V

Reputation: 35353

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

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

Upvotes: 14

Related Questions