4.5. String Literals in WMLScript
To define a string literal in WMLScript, enclose characters within double quotes or single quotes. For example, the following two lines are string literals that contain the words "WMLScript Tutorial":
"WMLScript
Tutorial"
'WMLScript Tutorial'
To defines an empty string, use "" (two consecutive double quotes) or '' (two consecutive single quotes).
Escape sequences can be placed in WMLScript string literals, just like what you can do with C++, Java and JavaScript. The backslash character \ is used to start an escape sequence. It is called the escape character and is combined with the character that follows to form an escape sequence. Escape sequences are needed if you want to place some special characters in a string literal. This is because some special characters are part of the WMLScript language. When the WMLScript engine encounters a special character, it needs a way to determine whether to treat the special character as part of the WMLScript language or as an ordinary character in a string.
Below is an example. To define a string literal that contains the words "DevelopersHome.com's WMLScript tutorial" with single quotes, you need to escape the ' character by putting a backslash before it, like this:
'DevelopersHome.com\'s WMLScript tutorial'
Note that there is no need to escape the ' character if you define the string literal using double quotes:
"DevelopersHome.com's WMLScript tutorial"
The following table shows some more examples of escape sequences:
Escape sequence |
Actual character represented by the escape sequence |
Code example |
Actual characters contained in the str variable |
\' |
' |
str = '\'WMLScript Tutorial\''; |
'WMLScript Tutorial' |
\" |
" |
str = "\"WMLScript Tutorial\""; |
"WMLScript Tutorial" |
\\ |
\ |
str = "\\WMLScript Tutorial\\"; |
\WMLScript Tutorial\ |
\n |
Newline character |
|
|
\r |
Carriage return character |
|
|
\b |
Backspace character |
|
|
\t |
Tab character |
|
|
Previous Page | Page 6 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