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

Preferences - Do not show ads

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:


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

Contents at a Glance (Click Here for Full Table of Contents)
Print this Web Page | | Back to Top

Feedback Form (Expand)

What do you think about this web page?

WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page