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
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
Google is your friend:
Anyway, if you’re just interested in the unicode escape sequences you can convert them yourself.
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
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?