String Data

A string value is a chain of zero or more concatenated, Unicode characters (letters, digits, and punctuation marks). The string data type represents text in JScript. To include string literals in your scripts, enclose them in matching pairs of single or double quotation marks. Double quotation marks can be contained within strings surrounded by single quotation marks, and single quotation marks can be contained within strings surrounded by double quotation marks. The following are examples of strings:

Using String Data

"The earth is round."
'"Come here, Watson. I need you." said Alexander.' 
"42"
"15th"
'c'

JScript provides escape sequences that you can include in strings to create characters that you cannot type directly. Each of these sequences begins with a backslash. The backslash is an escape character that informs the JScript interpreter that the next character is special.

Escape sequence

Meaning

\b

Backspace

\f

Form feed (rarely used)

\n

Line feed (newline)

\r

Carriage return. Use with the line feed (\r\n) to format output.

\t

Horizontal tab

\v

Vertical tab. Not compliant with ECMAScript standard and incompatible with Microsoft Internet Explorer 6.0.

\'

Single quote (')

\"

Double quote (")

\\

Backslash (\)

\n

ASCII character represented by the octal number n. The value of n must be in the range 0 to 377 (octal).

\xhh

ASCII character represented by the two-digit hexadecimal number hh.

\uhhhh

Unicode character represented by the four-digit hexadecimal number hhhh.

Any escape sequence not included in this table simply codes for the character that follows the backslash in the escape sequence. For example, "\a" is interpreted as "a".

Since the backslash itself represents the start of an escape sequence, you cannot directly type one in your script. If you want to include a backslash, you must type two sequential characters (\\).

'The image path is C:\\webstuff\\mypage\\gifs\\garden.gif.'

The single-quote and double-quote escape sequences can be used to include quotes in string literals. This example shows embedded quotes.

'The caption reads, \"After the snow of \'97. Grandma\'s house is covered.\"'

JScript uses the intrinsic char data type to represent a single character. A string containing one character or one escape sequence can be assigned to a variable of type char, although the string is not itself of type char.

A string that contains zero characters ("") is an empty (zero-length) string.

See Also

Reference

String Data Type (Visual Studio - JScript)

String Object

Concepts

JScript Expressions

Other Resources

Data in JScript