Skip to content

SUBSTRING: substring

The Substring function is used to extract a portion of a string based on either character index values or specific text markers. This function gives users the flexibility to extract a substring using numerical positions or reference texts, with the option to include or exclude the boundary markers.

Example 1: Using Start and End Text

Scenario: You have a string:
OrderID: #INV-98345-DELIVERED
You want to extract the portion between #INV- and -DELIVERED, which is 98345.

Steps to Configure

  1. Add a new step in your automation.
  2. From the Action dropdown, select Set a Variable Value.
  3. In the Element Key field, enter the variable name where the result will be stored (e.g., ExtractedText).
  4. Click on Form, then select Functions from the dropdown.
  5. From the function list, select SUBSTRING.
  6. Provide the following parameters:
    • inputString: Enter the full text string to extract from (e.g., OrderID: #INV-98345-DELIVERED)
    • type: Text (start and end markers).
    • inputStartIndex: Enter the start index or start text, based on the selected type (e.g., #INV-).
    • inputEndIndex: Enter the end index or end text, based on the selected type (e.g., -DELIVERED).
    • Include: Select Yes to include the start and end values in the result, or No to exclude them.
  7. Click Save.
Tabular View
Tabular View
Card View
Card View

Expected Outcome on Execution

  • The function extracts the text based on the specified range or text markers (e.g., 98345).
  • The result is saved in the variable specified in Element Key (e.g., ExtractedText).
  • This output can be referenced using ${VariableName} in later steps (e.g., ${ExtractedText}).

Example 2: Using Index Values

Scenario: You have a string from a web element that displays user information like:
Logged in as: Admin User

You want to extract just the word “Admin” from this text using character positions (index).

Steps to Configure

  1. Add a new step in your automation.
  2. From the Action dropdown, select Set a Variable Value.
  3. In the Element Key field, enter the variable name where the result will be stored (e.g., UserRole).
  4. Click on Form, then select Functions from the dropdown.
  5. From the function list, select SUBSTRING.
  6. Provide the following parameters:
    • inputString: Enter the full text string to extract from (e.g., Logged in as: Admin User)
    • type: Index (start and end markers).
    • inputStartIndex: Enter the start index based on the selected type (e.g., 14 as Index 14 is index before Admin).
    • inputEndIndex: Enter the end index, based on the selected type (e.g., 19 as Index 19 is index after Admin).
    • Include: Select Yes to include the start and end values in the result, or No to exclude them.
  7. Click Save.
Tabular View
Tabular View
Card View
Card View

Expected Outcome on Execution

  • The function extracts “Admin” and stores it in the variable you specified in the Element Key field (e.g., UserRole).
  • This output can be referenced using ${VariableName} in later steps (e.g., ${UserRole}).
  • Index positions start at 0.
  • Spaces and special characters are counted when calculating index values.
  • The characters at the inputStartIndex and inputEndIndex are included in the output when using Index type.

Back To Top