How can I decode HTML characters in C#?
I have email addresses encoded with HTML character entities. Is there anything in .NET that can convert them to plain strings?
You can use HttpUtility.HtmlDecode
If you are using .NET 4.0+ you can also use WebUtility.HtmlDecode
which does not require an extra assembly reference as it is available in the System.Net
namespace.
On .Net 4.0:
System.Net.WebUtility.HtmlDecode()
No need to include assembly for a C# project
As @CQ says, you need to use HttpUtility.HtmlDecode, but it's not available in a non-ASP .NET project by default.
For a non-ASP .NET application, you need to add a reference to System.Web.dll
. Right-click your project in Solution Explorer, select "Add Reference", then browse the list for System.Web.dll
.
Now that the reference is added, you should be able to access the method using the fully-qualified name System.Web.HttpUtility.HtmlDecode
or insert a using
statement for System.Web
to make things easier.