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

Text trim by defined characters

Block is used to remove characters from the start and the end of a source string. Every single character which has to be removed is searched in the string. Simultaneously, order of the defined characters does not matter.

Removing modes:

  • both sides: remove spaces from both sides of string,
  • left side: remove spaces from left side of string,
  • right side: remove spaces from right side of string.

Left part defines characters to remove in case of missing default white space characters are assumed. Source string is connected to the right part of the block and argument is required. Output of the block is a string with removed characters.

In case supplied string variable is not actually string returns None. In case supplied stripping value is not string default value of white spaces is assumed.

Block XML representation

XML representation of text_trim_text block

<xml xmlns="http://www.w3.org/1999/xhtml">
  <block type="text_trim_text">
    <field name="MODE">BOTH</field>
    <value name="STR">
      <block type="text">
        <field name="TEXT">input_string</field>
      </block>
    </value>
    <value name="TEXT">
      <block type="text">
        <field name="TEXT">trimming_chars</field>
      </block>
    </value>
  </block>
  <block type="text_trim_text">
    <field name="MODE">LEFT</field>
    <value name="STR">
      <block type="variables_get">
        <field name="VAR">input_var</field>
      </block>
    </value>
    <value name="TEXT">
      <block type="text">
        <field name="TEXT">trimming_chars</field>
      </block>
    </value>
  </block>
  <block type="text_trim_text">
    <field name="MODE">RIGHT</field>
    <value name="STR">
      <block type="variables_get">
        <field name="VAR">input_var</field>
      </block>
    </value>
    <value name="TEXT">
      <block type="variables_get">
        <field name="VAR">trimming_var</field>
      </block>
    </value>
  </block>
</xml>

Example of visual representation

Block "Trim string from"

Block “Trim string from”

Example of block usage

Example of "Trim string from" block

Example of “Trim string from” block

This block is used e.g. to remove redundant characters, which stay in the string after processing the message by a regular expression.

String “:administrator;” contains redundant colon and semicolon characters. To remove those characters from the string put “:;” to the block input and select both sides method.

Block is used three times in the example:

  • “set user_trim to … trim rot” row: removes “r”, “o” and “t” characters from the string “administrator”. Output is value “administra”.
  • “set user_trim to … trim tro” row: removes “t”, “r” and “o” characters from the string “administrator”. Output is value “administra”.
  • “set user_trim to … trim tdra” row: removes “t”, “d”, “r” and “a” characters from the string “administrator”. Output is value “ministrato”.

Processing result

Results of "Trim string from" block

Results of “Trim string from” block