Purpose
The substring task extracts a contiguous sequence of characters from a given string between a specified start and end index, or to the end of the string, and returns a substring.
Potential Use Case
Because substring returns a new string containing the extracted characters, you could use this method to extract only the telephone area code from an incoming string of phone number data.
Properties
| Incoming | Type | Description | 
|---|---|---|
| str | String | Required. The string that contains the substringthat will be extracted. | 
| indexStart | Number | Required. The position in the string to begin the extraction. Indexing starts (and defaults) at the zero (0) position (the beginning of str). | 
| indexEnd | Number | Optional. The position (up to, but not including) where to stop the extraction. Essentially, this property represents a "don't go beyond this point" value. If indexEndis not specified, the task will extract all the characters to the end of the string sinceindexEndalso counts from the beginning ofstrat the 0 position. | 
Note: If the value of
indexEndis less thanindexStart, then the effect is to swap the two properties. If the desired behavior is to return a blank value, see the Task Reference for splice (string).
| Outgoing | Type | Description | 
|---|---|---|
| substring | string | A new string containing the extracted part specified by the indexStartandindexEndparameters. | 
Examples
Example 1
In this IAP example:
- The - strvariable has been statically set to- 800-555-1212.
- The - indexStartvariable has been set to- 0, indicating the extraction should begin from the zero position of the- strvalue.
- The - indexEndvariable has been set to- 3, indicating the extraction should only proceed up to (not including) character position 3. Remember, indexing starts at zero (0), so character 3 in this case is the first hyphen ("-") in the string.
- The - substringoutput value will be- 800. 
Example 2
In this IAP example:
- The - strvariable has been statically set to- 800-555-1212.
- The - indexStartvariable has been set to- 4, indicating the extraction should begin from position 4 of the- strvalue.
- The - indexEndvariable has been set to- 7, indicating the extraction should only proceed up to (not including) character position 7. Remember, indexing starts at zero (0), so character 7 in this case is the second hyphen ("-") in the string.
- The - substringoutput value will be- 555.