Trimming trailing whitespace

The third keyword is trimright. As its name implies, trimright is used to trim trailing whitespace or other characters as specified.

The syntax of the string command is as follows:

	string trimright string characters

The trimright keyword will return string with all trailing whitespace trimmed if no characters are provided. If the optional characters are not specified only will be removed.

How to do it…

In the following example we will trim the trailing f characters from a string. Return values from the commands are provided for clarity. Enter the following command:


% string trimright "Now is the timef " f
Now is the time

How it works…

Tcl has trimmed all occurrences of the character f from the right side of the string. ...

Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.