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.
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.
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.
In this example:
str is statically set to 800-555-1212.indexStart is 0.indexEnd is 3, so extraction stops before character position three (the first hyphen "-").substring output is 800.
In this example:
str is statically set to 800-555-1212.indexStart is 4.indexEnd is 7, so extraction stops before character position seven (the second hyphen "-").substring output is 555.