Search code examples
c#windows-runtimehtml-entitieshtml-encode

Converting HTML entities to Unicode Characters in C#


I found similar questions and answers for Python and Javascript, but not for C# or any other WinRT compatible language.

The reason I think I need it, is because I'm displaying text I get from websites in a Windows 8 store app. E.g. é should become é.

Or is there a better way? I'm not displaying websites or rss feeds, but just a list of websites and their titles.


Solution

  • I recommend using System.Net.WebUtility.HtmlDecode and NOT HttpUtility.HtmlDecode.

    This is due to the fact that the System.Web reference does not exist in Winforms/WPF/Console applications and you can get the exact same result using this class (which is already added as a reference in all those projects).

    Usage:

    string s =  System.Net.WebUtility.HtmlDecode("é"); // Returns é