I have email addresses encoded with HTML character entities. Is there anything in .NET that can convert them to plain strings?
For strings containing   I've had to double-decode the string. First decode would turn it into the second pass would correctly decode it to the expected character.
On .Net 4.0:
System.Net.WebUtility.HtmlDecode()
No need to include assembly for a C# project
It is also worth mentioning that if you're using HtmlAgilityPack like I was, you should use HtmlAgilityPack.HtmlEntity.DeEntitize()
. It takes a string
and returns a string
.
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.