- string index string charIndex
- integer — The char specified at this integral index.
- end — The last char of the string.
- end-integer — The last char of the string minus the specified integer offset (e.g. end-1 would refer to the "c" in "abcd").
AMG: TIP #176 [1] adds two more more indexing modes: integer-integer and integer+integer. These are certainly convenient. However, due to the fundamental need for concatenation and reparsing in any practical application, they are also slightly slower than just using [expr] to do the math. (Remember to always brace your expr-essions!)There's also another mode which may be occasionally useful: end+integer. This comes in handy when the integer in question is already negative.
Returns for index an integer, the charIndex'th character in string. If index is end, the last character in string, and if index is end-integer, the last character minus the specified offset. (From the Tcl/Tk Reference Guide)
For example,
string index abcde 3returns "d" . Notice that the index is zero based - the first character is index 0.
string index abcde 10returns "" . There is no 10th character. No error is returned here.