O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required