The string Command

The string command is really a collection of operations you can perform on strings. The following example calculates the length of the value of a variable.

set name "Brent Welch"
string length $name
=> 11
					

The first argument to string determines the operation. You can ask string for valid operations by giving it a bad one:

string junk
=> bad option "junk": should be bytelength, compare,
						equal, first, index, is, last, length, map, match, range,
						repeat, replace, tolower, totitle, toupper, trim, trimleft,
						trimright, wordend, or wordstart
					

This trick of feeding a Tcl command bad arguments to find out its usage is common across many commands. Table 4-1 summarizes the string command

Table 4-1. The string command.
string bytelength ...

Get Practical Programming in Tcl & Tk, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.