trim ... (string function)

Prev Next

Function Names

trim, trim all, vtrim, vtrim all

Description

Trims excess white spaces (including tabs, new line symbols and other invisible control characters) from the beginning and end of the string. trim trims excessive spaces from beginning and ends, but leave spaces inside the string untouched.
trim all also removes redundant white blanks inside the string and replaces them by single spaces. I.e. new line symbols are also replaced by spaces.
Non-break space symbols are not affected.



Vectorization: The function names beginning with the prefix v support vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.
Note:For these functions, you need add the prefix letter 'v' in front of the function name. Otherwise the function recognizes a set and attempts to process sets and not strings. See trim [set function] for the corresponding set function.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1

Parameters

No.TypeDescription
1
input
valid types input string or value(s)

Attention: If 1st parameter is a set:

  • If the function name starts with the v prefix, the vectorization applies. Provide multiple values in a (nested) set to process all of them at once.
  • Otherwise, please refer to trim [set function] instead. Values of types other than string will be converted to strings first.

Return value

TypeDescription
string
set
trimmed string(s)

Excess white spaces removed according to function chosen. If vectorization has been applied, then the results are inside (nested) sets.

Examples

               echo( '"', trim    ( "  This   is a green  cat "), '"' );
               echo( '"', trim all( "  This   is a green  cat "), '"' );

Output

"This   is a green  cat"
"This is a green cat"
Try it yourself: Open LIB_Function_trim.b4p in B4P_Examples.zip. Decompress before use.

See also

trim [set function]