escape & unescape string function

var str="this is some text &')";
document.write(str);
document.write("<br>");
document.write(escape(str));
The output of the above code will be
this is some text &')
this%20is%20some%20text%20%26%27%29
We can use escape function in JavaScript to make a string portable to transmit it over a network. All the non ASCII characters are to be converted before sending them by using escape function. The escape function will replace these non ASCII characters to its two or four digit hex format.

The escape function converts a blank space into %20, same way it converts & to %26

After conversion we can get back the original string by using another JavaScript function unscape

Now data can be transmitted over net.
Now let us try to get back the original string by using unescape function. We will add one more line to the above code.
var str="this is some text &')";
document.write(str);
document.write("<br>");
document.write(escape(str));
document.write("<br>");
document.write(unescape(str));
The output of this is here ( only the last line ).
this is some text &') 
We got our original string.
JavaScript String Reference Uppercase to lower case by toLowerCase() method
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    manoj

    09-07-2015

    I have "&" in my query string(ex: str="avm=1&av=m&noj&ss=1"). With unescape I am doing split(unescape(str).split('&')), then I am not able to get back same key value pair. How can I get my string "m&noj" back in this scenario.

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer