String Literals in WMLScript

Preferences - Do not show ads

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

 

 


Page 6 of 71 Previous Page | Next Page
Contents at a Glance
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