The function SUBSTRING takes a base string and outputs a substring from the designated indexed location within it.
This function requires two pieces of input: one base String and one Number. It outputs another String: a substring of the base string, beginning at the index location designated by the given number. By default, this returned substring will consist of all of the base string's contents after the first indexed location, but SUBSTRING also accepts another optional Number as input, which designates another index location as the end of the substring. Indexing count begins at 0.
SUBSTRING(base_string, start, end) -> substring
base_string (required type: String)
The base string. This is where the substring will be pulled from.
start (required, type: Number)
The index number indicating at which character within the base string will begin the substring. Indexing count begins at zero.
end (optional, type: Number)
The index number indicating which character in the base string marks the end of the substring. The character occupying this location will not be included in the substring itself. Indexing count begins at zero.
If no value is given for this variable, the substring returned by SUBSTRING will contain all of the base string's contents after the character indexed start.
substring (type: String)
The designated fragment of the base string.
Designation is given by the index values start, and, if applicable, end. If no value is given for this variable, this string will contain all of the base string's contents after the character indexed start.
The following example takes the string "String" and returns the second character as well as everything after it. Note that indexing begins at 0, so the index 1 refers to the "t" in "String":
SUBSTRING("String", 1) -> "tring"
The following example takes the string "String" and returns everything from the second character to the third. Note that the fourth character in the base string – given by the index number 3 – marks the end of the returned substring, and is not, itself, present in the output:
SUBSTRING("String", 1, 3) -> "tr"