substring
  • 12 Aug 2024
  • Dark
    Light
  • PDF

substring

  • Dark
    Light
  • PDF

Article summary

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 to 800-555-1212.
  • The indexStart variable has been set to 0, indicating the extraction should begin from the zero position of the str value.
  • The indexEnd variable 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 substring output value will be 800.

01-substring

Example 2

In this IAP example:

  • The str variable has been statically set to 800-555-1212.
  • The indexStart variable has been set to 4, indicating the extraction should begin from position 4 of the str value.
  • The indexEnd variable 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 substring output value will be 555.

02-substring


Was this article helpful?

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.