decode html characters in c#

Anyone know how to decode html character codes such as ( & # x 0 0 4 0; ) in C# in Unity?

All examples I can find are using libraries that arent included.

Or maybe an idea on which library to include and how :wink:

Google is your friend:

Anyway, if you’re just interested in the unicode escape sequences you can convert them yourself.

  1. Search for “&#x” in the srting
  2. extract the numbers until “;”
  3. convert the hexnumber string to an int
  4. cast the int to char and you get your character

I would do something like this:

string DecodeHtmlChars(string aText)
{
    string[] parts = aText.Split(new string[]{"&#x"}, StringSplitOptions.None);
    for (int i = 1; i < parts.Length; i++)
    {
        int n = parts*.IndexOf(';');*

string number = parts*.Substring(0,n);*
try
{
int unicode = Convert.ToInt32(number,16)
parts = ((char)unicode) + parts*.Substring(n+1);*
} catch {}
}
return String.Join(“”,parts);
}
Haven’t tested it yet, but should work :wink:
edit Just remembered that the number is a hexadecimal string. Changed the code…

Someone grabbed the Mono-HttpUtility to use it in Unity: RestSharp-for-unity3d/RestSharp/Extensions/MonoHttp at master · Cratesmith/RestSharp-for-unity3d · GitHub

Import all three classes into your project, and use the RestSharp.Contrib namespace to call HttpUtility.HtmlDecode (yourHtmlTextToDecode);

string aaa = myText.Text;//text to decode.
string b = aaa.Replace(“&”, “WAT YOU WANT”);
myText.Text=b;

just use it on a void called by a button click.
We haven’t more datails for give best help: have u to replace stirung in a label,in a butto,or in other?