string trim
Gives a string with given characters removed at both ends.
string trim STRING ?CHARS?
Description
Removes each character of the set CHARS from the start and from the end of STRING, until a character outside the set. The characters inside the string stay. CHARS is a set: its order and its repeats do not matter.
With no CHARS the set is white space: the space, the tab, the line feed, the carriage return, the vertical tab, the form feed, the NUL character, and the Unicode spaces such as U+00A0 and U+2003. An empty CHARS removes no character.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| STRING | string | required | The text to trim. |
| CHARS | string | white space | The set of characters to remove. |
Returns
The new string.
Examples
% string trim " a b "
a b
% string trim abcXcba abc
X
% string trim " x "
x
% string trim abc ""
abc
Errors
% string trim abc x y
wrong # args: should be "string trim string ?chars?"
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1