Substring action

The Substring action in the String package enables you to extract a substring from a string.

Settings

  • In the Source string field, specify the source string.
  • In the Start from field, specify the starting point.
  • In the Length field, specify the length.
  • Select the Return blank if the range is not found option to have the output to show a blank value when the value in the Start from index field is greater than the source string.
    Note: The index count starts from 1.
  • In the Assign the output to variable list, specify the variable.

Example

Before you start building a bot, create a file in .txt format and save it as extract_substring.txt in the C:\Bot testing folder. Open the extract_substring.txt file and enter the text: Welcome to the Automation 360 platform and save it.

Create a sample bot and perform the following steps to extract a substring from a source string:
  1. Create a bot.
    1. On the left panel, click Automation.

      A list of available bots and forms is displayed.

    2. Click Create a bot.
    3. Enter the bot name: String_assign.
    4. Click Create and Edit.
  2. Open and read data from the .txt file.
    1. Double-click or drag the CSV/TXT > Open action.
      Note: The session name will be set to default.
    2. In the File path field, select the Desktop file option and click Browse to select your file.
    3. In the Delimiter tab, select the Comma check box.
    4. Double-click or drag the CSV/TXT > Read action.
    5. In the Assign value to the variable field, click the Create variable icon to create a variable.
    6. On the Create variable window, enter table_data in the Name field.
    7. Click Create and select.
    8. Double-click or drag the CSV/TXT > Close action to close the .txt file.
    9. In the Session name field, enter the session name that you used in the Open action to open the file.
  3. To extract a substring from the source string, double-click or drag the String > Substring action.
    1. In the Source string field, select $table_data[0][0]$.
    2. In the Start from field, enter 16.
    3. In the Length field, enter 14.
    4. In the Assign the output to variable field, click the Create variable icon to create a variable.
    5. On the Create variable window, enter substring_output in the Name field.
    6. Click Create and select.
  4. To print the values, double-click or drag the Message box action. In the Enter the message to display field, enter $substring_output$.
  5. Click Save and then Run.

    The bot extracts the specific substring from the source string and displays the output as Automation 360.

    Extract substring for a source string