Trimming leading whitespace
The second keyword is trimleft
. As its name implies, trimleft
is used to trim leading whitespaces or other characters as specified.
The syntax of the string
command is as follows:
string trimleft string characters
If no characters are provided, the trimleft
keyword will return string
with all leading whitespace trimmed. If the characters
(optional) are not specified, only the whitespaces will be removed.
How to do it…
In the following example, we will trim all leading whitespace from a string. Return values from the commands are provided for clarity. Enter the following command:
% string trimleft " Now is the time" Now is the time
How it works…
Tcl has returned a string with all leading whitespace removed.