Deniz Dogan
Deniz Dogan

Reputation: 26227

JavaScript: Replace hexadecimal character

I have a string such as "%2Fu%2F2069290%2F" in JavaScript (extracted from a web page). How do I get the human-readable version of that string?

Upvotes: 5

Views: 2057

Answers (4)

Johan Dahlin
Johan Dahlin

Reputation: 26546

Short version: Use decodeURIComponent().

Longer version: In older versions of JavaScript you could use unescape() but that has been deprecated since it only works properly for the LATIN1/ISO8859-1 codeset, so you really want to use decodeURIComponent() which is supported by all modern browsers.

 var c = decodeURIComponent("%2Fu%2F2069290%2F"));

Upvotes: 7

deubeulyou
deubeulyou

Reputation: 503

with unescape() ?

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039298

alert(decodeURIComponent("%2Fu%2F2069290%2F"));

Upvotes: 2

Mike Anchor
Mike Anchor

Reputation: 666

Use the unescape() function, eg:

alert(unescape("%2Fu%2F2069290%2F"));

Upvotes: 0

Related Questions