Extracts a section of a string and returns a new string.
String
slice(beginslice,endSlice)
beginSlice
The zero-based index at which to begin extraction.
endSlice
(Optional) The zero-based index at which to end extraction. If omitted, slice extracts to the end of the string.
slice extracts the text from one string and returns a new string. Changes to the text in one string do not affect the other string.
slice extracts up to but not including endSlice. string.slice(1,4) extracts the second character through the fourth character (characters indexed 1, 2, and 3).
As a negative index, endSlice indicates an offset from the end of the string. string.slice(2,-1) extracts the third character through the second to last character in the string.
The following example uses slice to create a new string.
The morning is upon us