开发者

How do i escape html unicode in .net?

In a webpage i got the text \u30ca\u30bf\u30ea\u30a2. It should translate to ナタリア. I just dont know how to do it in .NET. I tried HttpUtility.HtmlDecode an开发者_运维技巧d when that failed i tried HttpUtility.UrlDecode. No luck


Ok if your string is Escaped you will need to convert the string manually in to unicode.. or i have a better way. JSON accepts the Escaped Unicode chars and Convert it to normal chars 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 the output is :

Unicode Escaped: \u30ca\u30bf\u30ea\u30a2

Converted: ナタリア


And if you still want to do it manually n code . this answer with code on SO is what you want:

Convert a Unicode string to an escaped ASCII string

I don't want too take credit of posting his code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜