Top  | Previous | Next

Strings / substring

substring(string, startIndex, [endIndex])

Substring will return the portion of the string from the startIndex to the endIndex, or end of the string if endIndex is not specified. All indexes start at 0, so in the string "Test", "s" is at index 2. Indexes outside of the range of the string throw a StringIndexOutOfBoundsException.

 

substring("unhappy", 2)

... returns "happy"

 

substring("hamburger", 4, 8)

... returns "urge"