Coder Perfect

In C#, how can I decode HTML characters?

Problem

Email addresses have been encoded using HTML character entities. Is there a way to convert them to simple strings in.NET?

Asked by Vasil

Solution #1

HttpUtility.HtmlDecode can be used.

You can also use WebUtility if you’re using.NET 4.0 or higher. HtmlDecode, which is present in the System and does not require an additional assembly reference. The namespace of the internet.

Answered by Quintin Robinson

Solution #2

On .Net 4.0:

System.Net.WebUtility.HtmlDecode()

For a C# project, there’s no need to incorporate assembly.

Answered by Indy9000

Solution #3

You should use HttpUtility, as @CQ suggested. HtmlDecode is a useful tool, but it’s not included by default in non-ASP.NET projects.

A reference to System.Web.dll is required for non-ASP.NET applications. In Solution Explorer, right-click your project and choose “Add Reference,” then look for System.Web.dll in the list.

You should be able to access the method using the fully-qualified name System.Web.HttpUtility.HtmlDecode now that the reference has been added, or you can use a using statement for System.Web to make things easier.

Answered by OwenP

Solution #4

You can use HttpUtility if there is no Server context (i.e. you’re offline). HtmlDecode.

Answered by Rob Cooper

Solution #5

It’s also worth noting that, like me, if you’re using HtmlAgilityPack, you should keep using HtmlAgilityPack. HtmlEntity. DeEntitize(). It accepts a string and outputs another string.

Answered by Hypershadsy

Post is based on https://stackoverflow.com/questions/122641/how-can-i-decode-html-characters-in-c