string.slice()

Get the substring between two indexes of a String.

Signature

slice(start: Number) => String

slice(start: Number, end: Number) => String

Description

Extracts the substring between provided two zero-based offset indexes of the calling String.

Parameters

Parameter Type Required Description

start

Int

true

Starting index of the substring to extract (inclusive). The index is a zero-based offset, counted from the left. If this start index is greater than or equal to the length of the String, the method returns an empty String.

end

Int

true

Ending index of the substring to extract (exclusive). The index is a zero-based offset, counted from the left. If this end index is less than the start index, the method returns an empty String.

Return value

Type Description

String

Substring extracted from the calling String.

Examples

Get the subString from index 9 up to, but not including, 15:

"HTTP/1.1 200 OK".slice(9, 15)
"200 OK"
\