Strings
The “Strings” block is used for operations with strings.
The block properties contain fields for selecting a variable and the type of function.
Select a variable from the drop-down list in the first field. If the list is empty, it means that there are no variables in the current scenario. Create a variable in the “Variables” section, then return to the settings of this block.
After defining the variable to which the data in the block will be written, assign it a function from the list in the “Function type” field, which contains:
- Substring;
- Regular expression;
- Template.
Substring
A substring is a function that processes a string by extracting a specific fragment or substring from it.
In the section ‘Position’ indicates the initial index of the character in the source string from which the substring begins (counting starts from the zero position).
And the ‘Number of characters’ determines the length of this substring.
For example, there is a string: “Tomsk City”, and we want to get the substring “Tomsk”, then you can specify the position of the beginning of the substring:
1. The character ‘0’ is indicated in the position line;
2. The character count in this example is ‘5’.
Such functions can be used, for example, for text processing, when you need to extract a certain piece of information from a string.
When using this block, the value that will be in the variable after working with the Substring function will be changed. If you need to save the original data of this variable, you need to apply the function on another variable. To do this, in the “Variable” block, you need to equate the value of the desired variable to the one that will be used in this function.
Regular expression
Regular expressions are special sequences of characters that help in searching and manipulating text in strings.
When choosing this type of function, you must specify the regular expression itself, which will indicate which text you want to find or change.
List of regular expressions:
- Search for email addresses:
- ([a-zA-Z0-9._-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z0-9_-]+)
- Date search in the format “YYYY-MM-DD”:
- \b\d{4}-\d{2}-\d{2}\b
- Search for the year in YYYY format:
- \b\d{4}\b
- Search for strings containing only numbers:
- ^[0-9]+$
- Search for a string starting with a specific word:
- \bword\b.*
- Search for words starting with a certain letter:
- \b[Aa]\w*\b
- Extract keywords or phrases:
- \b(?:order|payment|delivery|problem)\b
- Checking the time in the format “HH:MM”:
- ([01]?[0-9]|2[0-3]):[0-5][0-9]
- Time search in the format “HH:MM:SS”:
- ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]
- Search for words containing a certain number of letters:
- \b\w{5}\b
- Search for strings that start with the letter “A” and contain exactly 3 characters:
- \bA\w{2}\b
Template
The Template function provides a mechanism for substituting the value of a variable into a string that contains a predefined marker.
An example of using the “Template” function type:
In order to use the template, you need to create variables, in this case two were created.
In the “Variable” block, you pass a variable, for example, named var2, and assign it the value “Hello! How are you? I hope everything is fine.”
Then, in the “Lines” block, you select the variable var1 and write the variable var2 in the template. In other words, you use the text that is stored in the var2 variable and embed it in a specific place in the text or template.
At the very end, in the Player block, you specify a variable containing text (for example, var1 or var2) to play or output this text. This will allow you to hear the contents of the variable that you have selected for playback.