slice (string)
  • 20 Dec 2023
  • Dark
    Light
  • PDF

slice (string)

  • Dark
    Light
  • PDF

Article summary

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.
Note:

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 as 800-555-1212.
  • The beginIndex variable has been set to 7, indicating the extraction should begin at the second dash in the str value.
  • The endIndex variable has been set to 4, 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 the endIndex value, the slicedString output variable will have the value of "" (an empty string).

sliceString-23.1-ex01


sliceString-23.1-ex02


sliceString-23.1-ex03

Example 2

In the second example shown below:

  • The str variable has been statically set as 800-555-1212.
  • The beginIndex variable has been set to 4, indicating the extraction should begin at position number 4 of the str value.
  • The endIndex variable has been set to 7, 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 of 555.

sliceString-23.1-ex06


sliceString-23.1-ex04


sliceString-23.1-ex05

For related information on the slice (string) task, see the slice (string) API reference.


Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.