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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data