slice (string)

Task purpose

Similar to the substring task, the slice (string) task extracts part of a string and returns the extracted part in a new string. The part to extract is specified by start and end indexes, or extends to the end of the string if no end index is provided.

Potential use case

Use this task when you need to extract a specific portion of a string — for example, extracting only the telephone area code from an incoming phone number string.

Properties

IncomingTypeDescription
strStringRequired. The string containing the value to extract.
beginIndexNumberRequired. The position at which to begin extraction. The first character is at position 0. Defaults to 0.
endIndexNumberOptional. The position at which to stop extraction. Extraction proceeds up to, but not including, this position.

If endIndex is less than beginIndex, slicedString returns an empty string (""). If this is not the desired behavior, consider using the substring task instead.

OutgoingTypeDescription
slicedStringStringThe portion of str between beginIndex and endIndex.

Examples

Example 1

In this example:

  • str is statically set to 800-555-1212.
  • beginIndex is 7 — extraction begins at the second dash.
  • endIndex is 4 — extraction would stop before character 4 (the first "5").
  • Because beginIndex is greater than endIndex, slicedString returns "" (an empty string).
slice (string) example 1 — configuration
slice (string) example 1 — incoming variables
slice (string) example 1 — empty string output

Example 2

In this example:

  • str is statically set to 800-555-1212.
  • beginIndex is 4 — extraction begins at the first "5".
  • endIndex is 7 — extraction stops before character 7 (the second "-").
  • slicedString returns 555.
slice (string) example 2 — configuration
slice (string) example 2 — incoming variables
slice (string) example 2 — output