Locating the word end
In a large character string, it may become necessary to know what is the end of a word. For example, we may require this information in order to determine where to extract data for a variable. To accomplish this, Tcl has provided the wordend
keyword.
The syntax of the string
command is as follows:
string wordend string index
This command will return the index of the first character that immediately follows the last character of the word contained within the string
that is located at the value passed in index
. In Tcl, a word is any contiguous range of alphanumeric characters (for example cat, dog, 123).
How to do it…
In the following example, we will determine the end of a word contained within a string. Return values from the commands are provided for clarity. Enter the following command:
% string wordend "Now is the time" 2 3
How it works…
Tcl returns the index for the character after the end of the word "Now".