- 20 Dec 2023
-
DarkLight
-
PDF
slice (string)
- Updated on 20 Dec 2023
-
DarkLight
-
PDF
Task Purpose
Similar to the substring task, the string slice task extracts part of a provided string and returns the extracted part in a new string. The part of the string you want to extract is specified between the start and end indexes, or to the end of the string.
Potential Use Case
If you need to extract only the telephone area code from an incoming string, using slice would provide the means by which to accomplish this.
Task Properties
Input and output properties are shown below.
Incoming | Type | Description |
---|---|---|
str |
String | Required. The string that contains the value to be extracted. |
beginIndex |
Number | Required. The position in the string to begin the extraction. The first character in the string has position 0, the second has position 1, and so on. Numbering starts (and defaults) at position '0' (the beginning of the str value). |
endIndex |
Number | Optional. The position in the string to stop the extraction. Numbering also begins from the start of the string and represents the point up to, but not including, where slicedString should end the extraction. |
If the value of endIndex
is less than the value of beginIndex
, the output value of slicedString
will return an empty string (""). If this is not the behavior that is desired, then consider using the substring
Task Reference.
Outgoing | Type | Description |
---|---|---|
slicedString |
String | The extracted value in str that is specified by the beginIndex and endIndex parameters. |
How to Configure the Task
Example 1
In the IAP example shown below:
- The
str
variable has been statically set as800-555-1212
. - The
beginIndex
variable has been set to7
, indicating the extraction should begin at the second dash in thestr
value. - The
endIndex
variable has been set to4
, indicating the extraction should only proceed up until (but not including) character 4. Remember, character numbering starts at '0', so character 4 in this case is the first number "5" character. - Because the
beginIndex
value is greater than theendIndex
value, theslicedString
output variable will have the value of""
(an empty string).
Example 2
In the second example shown below:
- The
str
variable has been statically set as800-555-1212
. - The
beginIndex
variable has been set to4
, indicating the extraction should begin at position number 4 of thestr
value. - The
endIndex
variable has been set to7
, indicating the extraction should only proceed up until (but not including) character 7. Remember, numbering starts at '0', so character 7 in this case is the second "-" character. - The
slicedString
output variable will have the value of555
.
Related Information
For related information on the slice (string) task, see the slice (string) API reference.