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
string bytelength ... |
Get Practical Programming in Tcl & Tk, Third Edition 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.