JScript String Object

A String object in JScript represents textual data such as words and sentences. String objects are rarely created explicitly with the new operator because they are usually created implicitly by assigning a string literal to a variable. For more information, see String Object.

Using the String Object

The String object has many built-in methods. One of these is the substring method, which returns part of the string. It takes two numbers as its arguments. The first number is the zero-based index that indicates the beginning of the substring, and the second number indicates the end of the substring.

var aString : String = "0123456789";
var aChunk : String = aString.substring(4, 7);  // Sets aChunk to "456".

The String object also has a length property. This property contains the number of characters in the string (0 for an empty string). This a numeric value and can be used directly in calculations. This example obtains the length of a string literal.

var howLong : int = "Hello World".length  // Sets the howLong variable to 11.

See Also

Concepts

String Data

Reference

String Object

Other Resources

Intrinsic Objects