Compare unescape(), decodeURI(), and decodeURIComponent() | SJB -->

This website uses cookies to ensure you get the best experience. More info...

Pages

Compare unescape(), decodeURI(), and decodeURIComponent()

Compare unescape(), decodeURI(), and decodeURIComponent() | Virtual Species
unescape() Method
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
We know that escape() method returns a string of the argument with all spaces, punctuation, accented characters and any non-ASCII characters replaced with %HexNumber. The function unescape() does simply the opposite. It takes the encoded version of a string and reverse the string back to its decoded original state. By the way, both of these methods does not work with Unicode strings and both have been deprecated. The syntax of this function is_
     unescape(string);
For examine, using escape() on the Test Characters will give the following encoded string. Using this encoded string in the input box and decoding will return the original Test String.
     %7E%21@%23%24%25%5E%26*%3D+%28%29%7B%7D%5B%5D%2C%3F/%3A%3B%27%22%5C


decodeURI() Method
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
The decodeURI() method does the opposite of the encodeURI() method. The encodeURI() method returns encoded string and decodeURI() decode the string as it's decoded original version. The syntax of this function is_
     decodeURI(string);
We have discussed on other post that encodeURI() does not encode all the characters (Find More Here). So, some characters don't need to be decoded. Below is the encoded form of our Test Characters. We can copy this in our textbox and by decoding it with the decode button, we will find the original form of the Test Characters.
     ~!@#$%25%5E&*=+()%7B%7D%5B%5D,?/:;'%22%5C

decodeURIComponent() Method
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
The encodeURIComponent() function encodes portion of URI by replacing each instance of certain characters by one, two or three of escape sequences. The escape sequences represent the UTF-8 encoding of the characters. We use decodeURIComponent() to reverse the the string encoded by encodeURIComponent(). The syntax of this function is_
     decodeURIComponent(string);
Use decodeURIComponent() to decode every strings that encoded with UTF-8 encoding. Below is the encoded form of our Test Characters using this function. Take this encoded string and put into textbox to decode using decode button will generate the original Test Characters.
     ~!%40%23%24%25%5E%26*%3D%2B()%7B%7D%5B%5D%2C%3F%2F%3A%3B'%22%5C

URI DECODER
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
Decode your URI using all the methods mentioned above_
[ Outputs will be the decoded values of encoded Test Characters unless value is provided ]


unescape():

decodeURI():

decodeURIComponent(): (recommended)

Check out Compare escape(), encodeURI(), and encodeURIComponent()

No comments:

Post a Comment