What is C # equivalent to javascript unescape ()?

I am trying to parse some JavaScript and one line

 var x = unescape("%u4141%u4141 ......"); 

with a large number of characters in the form %uxxxx .

I want to rewrite JavaScript in c# , but cannot determine the appropriate function to decode a string of characters like this. I tried

 HttpUtility.HTMLDecode("%u4141%u4141"); 

but that did not change these characters at all.

How can I accomplish this in C #?

+8
javascript c #
source share
6 answers

You can use UrlDecode :

 string decoded = HttpUtility.UrlDecode("%u4141%u4141"); 

decoded will contain "䅁䅁" .

As others have pointed out, changing % to \ will work, but UrlDecode is the preferred method as it ensures that other escaped characters will also be correctly translated.

+13
source share

You need HttpUtility.UrlDecode . In most cases, you should not use escape/unescape in most cases at present, you should use things like encodeURI/decodeURI/encodeURIComponent .

When should you use escape instead of encodeURI / encodeURIComponent?

This question covers the question of why escape/unescape is a bad idea.

+4
source share

You can call the bellow method to achieve the same effect as the javascript escape / unescape method

 Microsoft.JScript.GlobalObject.unescape(); Microsoft.JScript.GlobalObject.escape(); 
+2
source share

Change the% signs to a backslash and you have a C # string literal. C # treats \ uxxxx as an escape sequence, with xxxx having 4 digits.

0
source share

In the main use of strings, you can initiate a string variable in Unicode: var someLine = "\ u4141"; If possible, replace all "% u" with "\ u".

0
source share

edit web.config the following parameter:

< globalization requestEncoding="iso-8859-15" responseEncoding="utf-8" >responseHeaderEncoding="utf-8" in < system.web >

0
source share

All Articles