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
|
|
|
Feedback Form (ExpandCollapse)
|
|