Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the c# equivalent to javascript's unescape()?

I am trying to analyse some JavaScript, and one line is

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

with lots of characters in form %uxxxx.

I want to rewrite the JavaScript in c# but can't figure out the proper function to decode a string of characters like this. I've tried

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

but this did not change these characters at all.

How can I accomplish this in c#?

like image 450
vivek a. Avatar asked Jul 26 '11 17:07

vivek a.


People also ask

What is C used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C language in simple words?

C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is computer C language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.

Why is C called C?

C is a general purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. It was named 'C' because many of its features were derived from an earlier language called 'B'.


2 Answers

You can use UrlDecode:

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

decoded would then contain "䅁䅁".

As other have pointed out, changing the % to \ would work, but UrlDecode is the preferred method, since that ensures that other escaped symbols are translated correctly as well.

like image 150
dlev Avatar answered Sep 21 '22 01:09

dlev


You need HttpUtility.UrlDecode. You shouldn't really be using escape/unescape in most cases nowadays, you should be using things like encodeURI/decodeURI/encodeURIComponent.

When are you supposed to use escape instead of encodeURI / encodeURIComponent?

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

like image 37
andynormancx Avatar answered Sep 22 '22 01:09

andynormancx