Language Reference substring Method


Description

Retrieves the substring at the specified location within the string object.

Syntax

strVar = strVariable.substring( start, end )
strVar = "String Literal".substring( start, end )

Arguments

start: The zero-based index indicating the beginning of the desired substring.
end: The zero-based index indicating the end of the desired substring.

Return Value

A string object containing the substring derived from the original string object.

Remarks

substring will use the lower of start and end as the beginning point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) will return the same substring.

The only exception to this is for negative parameters. If the first parameter is less than zero, it will be treated as zero. If the second parameter is negative, it will be set to the value of the first parameter.

The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in the examples in the first paragraph is three.

start and end can be strings. These strings will be coerced into integers if possible. If not, the value of the parameter is treated as zero.