

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to decode an encoded string in JavaScript?
Decoding
In JavaScript, to decode a string unescape() method is used. This method takes a string, which is encoded by escape() method, and decodes it. The hexadecimal characters in a string will be replaced by the actual characters they represent using unescape() method.
Syntax
unescape(string)
Example
In the following the two exclamation marks have converted to hexadecimal characters using escape() method. Later on those marks were decoded in to their natural characters using unescape() method.
<html> <body> <script type="text/javascript"> // Special character encoded with escape function var str = escape("Tutorialspoint!!"); document.write("</br>"); document.write("Encoded : " + str); // unescape() function document.write("Decoded : " + unescape(str)) </script> </body> </html>
Output
Encoded : Tutorialspoint%21%21 Decoded : Tutorialspoint!!
There is an exception that the characters .(dot) and @ wont convert in to hexadecimal characters. For instance, in the following code when escape() method is used all the characters have converted to hexadecimal except .(dot) and @.
Example
<html> <body> <script type="text/javascript"> str = escape("My gmail address is robbinhood@rocketmail.com") document.write("Encoded : " + str); document.write("</br>"); // unescape() function document.write("Decoded : " + unescape(str)) </script> </body> </html>
Output
Encoded : My%20gmail%20address%20is%20robbinhood@rocketmail.com Decoded : My gmail address is robbinhood@rocketmail.com
- Related Questions & Answers
- To decode string array values that is already encoded in Numpy
- C++ Program to Decode a Message Encoded Using Playfair Cipher
- Function to decode a string in JavaScript
- How to decode a string after encoding in JavaScript?
- How to decode the string in android?
- Decode String in C++
- Java Program to decode string to integer
- How to decode a URL using JavaScript function?
- How to encode and decode a URL in JavaScript?
- How to decode a job advertisement?
- How to set default text encoded for android webview?
- How to convert an array into JavaScript string?
- How to convert wrongly encoded data to UTF-8 in MySQL?
- How to decode JSON into objects in Golang?
- Converting string to an array in JavaScript
Advertisements