Note, string concatenation and regular expressions are handled in separate pages.
Note that doing equality checks via a generic Compare with integer result is not only confusing for the programmer but is often a significantly more expensive operation; this is especially true when using "C-strings".
APL can use regular expressions directly: Alternatively, a functional approach combining Boolean masks that filter away leading and trailing spaces: Or reverse and remove leading spaces, twice: In AWK, one can use regular expressions to trim: or: There is no standard trim function in C or C++.
Another open source C++ library Qt, has several trim variants, including a standard one:[57] The Linux kernel also includes a strip function, strstrip(), since 2.6.18-rc1, which trims the string "in place".
[58] A trim algorithm in Haskell: may be interpreted as follows: f drops the preceding whitespace, and reverses the string.
The trim algorithm in J is a functional description: That is: filter (#~) for non-space characters (' '&~:) between leading (+./\) and (*.)
In earlier versions it can be added to the String object's prototype as follows: Perl 5 has no built-in trim function.
Example: The Tcl string command has three relevant subcommands: trim, trimright and trimleft.
For each of those commands, an additional argument may be specified: a string that represents a set of characters to remove—the default is whitespace (space, tab, newline, carriage return).
Example of trimming vowels: XSLT includes the function normalize-space(string) which strips leading and trailing whitespace, in addition to replacing any whitespace sequence (including line breaks) with a single space.
Example: XSLT 2.0 includes regular expressions, providing another mechanism to perform string trimming.