Locating the index of a character

What if we need to determine which character exists at a specific location within a string and not just the first instance? To accomplish this, string, includes the index keyword.

The syntax for the string command is as follows:

	string index string index

When invoked with the index keyword, the string command returns the character that exists at the location specified in the switch. The accepted values are valid for all the Tcl commands that accept an index and may be passed as follows:

Value

Description

Any integer value

Integer value for a specific index.

Please note that the index is 0-based.

end

The last character in the string.

end-n

The last character in the string minus the numeric offset represented ...

Get Tcl/Tk 8.5 Programming Cookbook 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.