substring
The substring task extracts a contiguous sequence of characters from a string between a specified start and end index (or to the end of the string) and returns a new substring. The original string is not modified.
Potential use case
Because substring returns a new string containing the extracted characters, you can use it to extract only the telephone area code from an incoming string of phone number data.
Properties
If indexEnd is less than indexStart, the effect is to swap the two values. If you need to return a blank value instead, see the splice (string) task.
Example 1
In this example:
- The
stris statically set to800-555-1212. - The
indexStartis0. - The
indexEndis3, so extraction stops before character position three (the first hyphen"-"). - The
substringoutput is800.

Example 2
In this example:
- The
stris statically set to800-555-1212. - The
indexStartis4. - The
indexEndis7, so extraction stops before character position seven (the second hyphen"-"). - The
substringoutput is555.
