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

IncomingTypeDescription
strStringRequired. The string containing the substring to extract.
indexStartNumberRequired. The position in the string to begin extraction. Indexing is zero-based (defaults to 0).
indexEndNumberOptional. The position up to (but not including) where extraction stops. If not specified, the task extracts all characters to the end of the string.

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.

OutgoingTypeDescription
responseStringThe extracted substring.

Example 1

In this example:

  • The str is statically set to 800-555-1212.
  • The indexStart is 0.
  • The indexEnd is 3, so extraction stops before character position three (the first hyphen "-").
  • The substring output is 800.
substring task configured to extract the area code 800 from the phone number string

Example 2

In this example:

  • The str is statically set to 800-555-1212.
  • The indexStart is 4.
  • The indexEnd is 7, so extraction stops before character position seven (the second hyphen "-").
  • The substring output is 555.
substring task configured to extract 555 from the middle of the phone number string