Use the Substring action in the String package to extract a substring from a string.
Settings
- In the Actions palette, double-click or drag the Substring action from the String package
- In the Source string field, specify the source string.
- In the Start from field, specify the index from where you
want to start extracting the substring.Note: The index starts from 1.
- In the Length field, specify the length.
- Select the Return blank if the range is not found option to display a blank value when the Start from index exceeds the source string length.
- In the Assign the output to variable list, specify the output variable.
Example
This example shows how to extract Automation 360 from the string Welcome to the Automation 360 platform using the Substring action.
Before building the bot, create extract_substring.txt in C:\Bot testing.
Open the file and enter the following text: Welcome to the Automation 360 platform
- Create a bot.
- On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create a bot.
- Enter the bot name: String_assign.
- Click Create and Edit.
- On the left panel, click Automation.
- Open and read data from the .txt file.
- Double-click or drag the
action.Note: The session name will be set to default.
- In the File path field, select the Desktop file option and select Browse to locate your file.
- In the Delimiter tab, select the Comma check box.
- Double-click or drag the action.
- In the Assign value to the variable field, click the Create variable icon to create a variable.
- In the Create variable dialog, enter table_data in the Name field.
- Click Create and select.
- Double-click or drag the action to close the .txt file.
- In the Session name field, enter the session name that you used in the Open action to open the file.
- Double-click or drag the
action.
- Extract a substring from the source string.
- Double-click or drag the action.
- In the Source string field, select the variable $table_data[0][0]$.
- In the Start from field, enter 16.
- In the Length field, enter 14.
- In the Assign the output to variable field, click the Create variable icon to create a variable.
- In the Create variable dialog, enter substring_output in the Name field.
- Click Create and select.
- Double-click or drag the Message box action. In the Enter the message to display field, enter $substring_output$.
- Click Save and then Run.
The bot extracts Automation 360 from the source string and displays it in the message box.