Prototype: string_trim(string)

Return type: string

Description: Trim whitespace from beginning and end of string.

Arguments:

  • string: string - Input string - in the range: .*

Example:

bundle agent example_trim
{
  vars:
      "my_string_one" string => string_trim( "  Trim spaces please   ");
      "my_string_two" string => string_trim( "
        Trim newlines also please

      ");

  reports:
      "my_string_one: '$(my_string_one)'";
      "my_string_two: '$(my_string_two)'";
}

bundle agent __main__
{
  methods: "example_trim";
}
R: my_string_one: 'Trim spaces please'
R: my_string_two: 'Trim newlines also please'

This policy can be found in
`/var/cfengine/share/doc/examples/string_trim.cf`
and downloaded directly from
<a href="https://raw.github.com/cfengine/core/master/examples/string_trim.cf" target="_blank">github</a>.

**History:** Introduced in CFEngine 3.16

**See also:** [string_head()](/reference/functions/string_head "string_head"), [string_tail()](/reference/functions/string_tail "string_tail") [string_length()](/reference/functions/string_length "string_length"), [string_reverse()](/reference/functions/string_reverse "string_reverse").