Locating the word start
While it is all well and good that we know where our word ended, what if we need to know where it starts? To accomplish this, Tcl has provided the wordstart
keyword.
The syntax of the string
command is as follows:
string wordstart string index
This command will return the index of the first character of the word contained within string
that is located at the value passed in index
.
How to do it…
In the following example, we will determine the start of a word contained within a string. Return values from the commands are provided for clarity. Enter the following command:
% string wordstart "Now is the time" 12 11
How it works…
As you can see, Tcl has returned the index for the first character of the word "time".