String.substring() (Method)

Extracts a portion of a string.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise server - 2.0
Opera - 3.0
Property/method value type:String primitive
JavaScript syntax:-myString.substring(aStartPosition, anEndPosition)
Argument list:anEndPositionA location within the string to end the sub-string extraction. If this is omitted then the end of the string is assumed to be the end position.
aStartPositionA location within the string to begin the sub-string extraction.

If only one argument is provided, this method returns a sub-string starting at the indicated character position and proceeding to the end of the string. Where two arguments are provided the start and end points of the string are used to slice out a portion and return just that part.

When just one argument is provided, the second is supplied internally and is taken to be end of the string.

Where an argument is actually NaN rather than a meaningful value, then Zero is used instead.

If any argument is greater than the length of the string, then the length of the string is used instead.

Where the start point is larger than the end point, the two values are swapped over.

This method is intentionally generic and can be applied to non-string objects. Where necessary, the receiving object may be converted to a string so that a sub-string can be extracted.

The result returned by this method is the sequence of characters between the start and end positions of the source string. The value returned is a string primitive.

See also:String.prototype, String.slice(), String.split(), String.substr()

Cross-references:

ECMA 262 edition 2 - section - 15.5.4.9

ECMA 262 edition 2 - section - 15.5.4.10

ECMA 262 edition 3 - section - 15.5.4.15