20.2. Escaping and Unescaping Special Characters in URLs: escapeString() and unescapeString() Functions

The escapeString() function helps us escape special characters in URLs. It replaces special characters (such as ?, &, =, etc) with their corresponding hexadecimal escape sequence according to the rules of URL escaping. For example, the escapeString() function replaces the & character with %26. The unescapeString() function helps us reverse what is done by escapeString(). For example, it replaces %26 with the & character.

The syntax of escapeString() and unescapeString() is shown below:


URL.escapeString(value);
URL.unescapeString(value);


If any error occurs during the function call, invalid is returned. For example, if value has characters that the functions cannot handle, then invalid is returned. On most mobile devices, the two functions can handle US-ASCII characters properly.

The following WMLScript example demonstrates the usage of escapeString() and unescapeString():


var x = URL.escapeString("Hello, welcome to our WMLScript tutorial.");
var y = URL.unescapeString(x);


After the execution of the above code, x has the string value "Hello%2C%20welcome%20to%20our%20WMLScript%20tutorial." and y has the string value "Hello, welcome to our WMLScript tutorial.".


Previous Page Page 63 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page