6

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 and when that failed i tried HttpUtility.UrlDecode. No luck

  • ok what is the output you are getting (or error)... that will help us in tracking down the problem.. better if you can show us the code you are trying.. may be it has some problems with Base64 conversions.. or UTF16 chars.. can you provide more details – Shekhar_Pro Feb 14 '11 at 00:24

1 Answers1

2

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.

Community
  • 1
  • 1
Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
  • 1
    I think they're saying they have a string that contains the backslashes. You know, like this: `string d = @"\u30ca\u30bf\u30ea\u30a2";`. Then they're wondering how to unescape `d`. – icktoofay Feb 14 '11 at 00:32
  • @icktoofay ok i have changed my answer for that.. and who ever downvoted me can remove his vote – Shekhar_Pro Feb 14 '11 at 00:51