Logmanager documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Text get substring

This block is used to get a specific part of substring from input string. Left part defines the source string.

Options

Left block selector of the substring:

  • letter #: start of the substring is from character x of source string,
  • letter # from end: start of the substring is from character x from the end of source string,
  • first letter: start of substring is from the first character of source string.

Right block selector defines the end of the substring:

  • letter #: end of substring is at character x of source string,
  • letter # from end: end of substring is at character x from the end of source string,
  • last letter: end of substring is at the last character from source string.

Block requires a variable containing a string, and accepts two integer positions.

If the input variable is not a string, or if the position argument is missing or not an integer, the block returns None.

First letter is on position 0. So in the string “abcd”, letter “a” is on position “0” and letter “d” is on position “3”.

Result of the selection “letter on position 0 to letter on position 3” is “abc”, because the letter on the last position is excluded.

#Block XML representation

XML representation of the text_get_substring block

<xml xmlns="http://www.w3.org/1999/xhtml">
  <block type="text_get_substring">
    <mutation at1="true" at2="true"/>
    <field name="WHERE1">FROM_START</field>
    <field name="WHERE2">FROM_START</field>
    <value name="STRING">
      <block type="variables_get">
        <field name="VAR">text</field>
      </block>
    </value>
    <value name="AT1">
      <block type="math_number">
        <field name="NUM">0</field>
      </block>
    </value>
    <value name="AT2">
      <block type="math_number">
        <field name="NUM">12</field>
      </block>
    </value>
  </block>
</xml>

Example of visual representation

Block "In text get substring"

Block “In text get substring”

Example of block usage

Example of "In text get substring" block

Example of “In text get substring” block

User name is acquired from the source message in this example.

Block is used on the “set user_part to” and “to in text user_part” rows in the example:

  • “In text find” block reads value of the message raw and finds last occurrence of “user:” string.
  • Result is value “72”.
  • This value is used in next “In text get substring” block, where string “user: administrator” is loaded.
  • String is saved into the “user_part” variable.
  • “user_part” variable is used in the next “In text get substring” block.
  • Output is value “administrator”.

Input data

Login permitted from 192.168.10.1/1234 to inside:192.168.1.1/https for user: administrator

Processing result

Results of "In text get substring" block

Results of “In text get substring” block