Search code examples
c#xamarinhtmldecode

C# how to decode html character squared ($sup2)


I am getting a string "lb/in&sup2" (which I want to show as lb/in²) from server. I want to decode this and show it in my Xamarin.iOS app.

I tried:

System.Net.WebUtility.HtmlDecode("lb/in&sup2")

but its not working, still shows as "lb/in&sup2".


Solution

  • Html entity should end with ";" character. This should work fine:

    System.Net.WebUtility.HtmlDecode("lb/in²");
    

    If you are getting string exactly as you posted - you should fix the side which you are getting this string from, because "&sup2" is not html entity, it's just a "&sup2" string.