substr Method

Returns a substring beginning at a specified location and having a specified length.

function substr(start : Number [, length : Number]) : String

Arguments

  • start
    Required. The starting position of the desired substring. The index of the first character in the string is zero.

  • length
    Optional. The number of characters to include in the returned substring.

Remarks

If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of the string.

Example

The following example illustrates the use of the substr method.

function SubstrDemo(){
    var s = "The quick brown fox jumps over the lazy dog.";
    var result = s.substr(10, 5);  
// Returns "brown".
    return(result); 
}

Requirements

Version 3

Applies To:

String Object

See Also

Reference

substring Method

Change History

Date

History

Reason

March 2009

Modified example.

Information enhancement.