substring
- 12 Aug 2024
-
DarkLight
-
PDF
substring
- Updated on 12 Aug 2024
-
DarkLight
-
PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
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
Input and output properties are referenced below.
Incoming | Type | Description |
---|---|---|
str |
String | Required. The string that contains the substring that 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 indexEnd is not specified, the task will extract all the characters to the end of the string since indexEnd also counts from the beginning of str at the 0 position. |
If the value of indexEnd
is less than indexStart
, 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 |
---|---|---|
response |
String | Response output from the stub. |
Example 1
In this IAP example:
- The
str
variable has been statically set to800-555-1212
. - The
indexStart
variable has been set to0
, indicating the extraction should begin from the zero position of thestr
value. - The
indexEnd
variable has been set to3
, 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
substring
output value will be800
.
Example 2
In this IAP example:
- The
str
variable has been statically set to800-555-1212
. - The
indexStart
variable has been set to4
, indicating the extraction should begin from position 4 of thestr
value. - The
indexEnd
variable has been set to7
, 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
substring
output value will be555
.
Was this article helpful?