0

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

2
  • What do you mean by “decode UTF-16 strings”? JS strings are already UTF-16 Commented Jul 29, 2016 at 9:55
  • I am getting some encoded string "Acesse%20j%E1" but when i try to decode it using decodeURI(), i am not getting any result. How can i decode it? UTF16 is just i found while i was searching for the type of encoding toi the string Commented Jul 29, 2016 at 9:57

1 Answer 1

3

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á'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.