Nitesh Kumar Singh
Nitesh Kumar Singh

Reputation: 143

Decode UTF16 encoded string (URL) in Java Script

I have string that is encoded in UTF16 and i want to decode it using JS, when i use simple decodeURI() function i get the desired result but in case when special characters are there in the string like á, ó, etc it do not decodes. On more analysis i came to know that these characters in the encoded string contains the ASCII value.

Say I have string "Acesse já, Encoded version : "Acesse%20j%E1". How can i get the string from the encode version using java script?

EDIT: The string is a part of URL

Upvotes: 0

Views: 2435

Answers (1)

Iso
Iso

Reputation: 3238

Ok, your string seems to have been encoded using escape, use unescape to decode it!

unescape('Acesse%20j%E1');              // => 'Acesse já'

However, escape and unescape are deprecated, you’d better use encodeURI or encodeURIComponent here.

encodeURIComponent('Acesse já');        // => 'Acesse%20j%C3%A1'
decodeURIComponent('Acesse%20j%C3%A1'); // => 'Acesse já'

Upvotes: 3

Related Questions