How can I avoid html unicode in .net?

On the webpage, I got the text \ u30bf \ u30ea \ u30a2. He must translate to ナ タ リ ア. I just don't know how to do this in .NET. I tried HttpUtility.HtmlDecode, and when that failed, I tried HttpUtility.UrlDecode. Bad luck

+6
html c # escaping decode
source share
1 answer

Well, if your string is Escapeed, you will need to convert the string manually to unicode .. or I have a better way. JSON accepts Escaped Unicode characters and converts them to regular characters, so try this (the JavaScriptSerializer is in System.Web.Script.Serialization in System.Web.Extensions.dll ).

 string d = @"\u30ca\u30bf\u30ea\u30a2"; Console.WriteLine("Unicode Escaped:" + d); JavaScriptSerializer jr = new JavaScriptSerializer(); string dt = jr.Deserialize<string>("\"" + d + "\""); Console.WriteLine("Converted:" + dt); 

and output:

 Unicode Escaped: \u30ca\u30bf\u30ea\u30a2 Converted: ナタリア 

<h / "> And if you still want to do it manually, enter the code. this answer with the SO code is what you want:

Convert Unicode string to escaped ASCII string

I do not want to take too much credit for sending his code.

+1
source share

All Articles