In this chapter, we will cover:
When I first started using Tcl, everything I read or researched stressed the mantra "Everything is a string". Coming from a hard-typed coding environment, I was used to declaring variable types and in Tcl this was not needed. A set
command could—and still does—create the variable and assigns the type on the fly. For example, set variable "7
" and set variable 7
will both create a variable containing 7
. However, with Tcl, you can still print the variable containing a numeric 7
and add 1
to the variable containing a string representation of 7
.
It still holds true today that everything in Tcl is a string. When we explore the Tk Toolkit and widget creation, you will rapidly see that widgets themselves have a set of string values that determine their appearance and/or behavior.
As a pre-requisite for the recipes in this chapter, launch the Tcl shell as appropriate for your operating system. You can access Tcl from the command line to execute the commands.
As with everything else we have seen, Tcl provides a full suite of commands to assist in handling string expressions. However due to the sheer number of commands and subsets, I won't be listing every item individually in the following section. Instead we will be creating numerous recipes and examples to explore in the following sections. Please refer to the Tcl/Tk Commands listing at the end of this book. A general list of the commands is as follows:
Command |
Description |
---|---|
|
The string command contains multiple keywords (see the section covering the command) allowing for manipulation and data gathering functions. |
|
Appends to a string variable. |
|
Format a string in the same manner as C sprint. |
|
Regular expression matching. |
|
Performs substitution, based on Regular expression matching. |
|
Parses a string using conversion specifiers in the same manner as C sscanf. |
|
Perform backslash, command, and variable substitution on a string. |
Using the commands listed in the table, a developer can address all their needs as applies to strings. In the following sections, we will explore these commands as well as many subsets of the string
command.
3.145.178.151