- string first string1 string2 ?startIndex?
string first a 0a23456789abcdef 5will return “10”, but
string first a 0123456789abcdef 11will return “-1”.
Example:
A wish for Tcl 8.5+ or 9.0Somehow let string first be flagged -nocase. Perhaps allowing the flag at the end where it can't be confused with and can co-exist with the starting index. Alternatively: allow string match to return the index at which the match occurred. -- Roy Terry, 7 January, 2004
-- RS same day: Isn't that duplicating what we have in
string first a 0a23456789abcdefreturns “1” (notice this is again a zero based value).
string first "a" "0a23456789abcdef" 5returns “10”.This example uses the startIndex to indicate that the searching should begin at the fifth character (a 4 in the example). However the result is still a zero based index from the beginning of the string!
string first a 0123456789abcdef 11returns a “-1”, the standard return if the string being sought is not found. An error is generated if the index is not an integer or end?-integer?.
A wish for Tcl 8.5+ or 9.0Somehow let string first be flagged -nocase. Perhaps allowing the flag at the end where it can't be confused with and can co-exist with the starting index. Alternatively: allow string match to return the index at which the match occurred. -- Roy Terry, 7 January, 2004
-- RS same day: Isn't that duplicating what we have in
regexp -nocase -start 11 -inline a 0123456789abcdefSure it is and the desire is for efficiency and also the consistency of having more string commands respect no case. There is already huge overlap between what you can do with string and regexp. In fact, you could surely write all the string commands in pure Tcl using regexp, regsub. - RoyDKF: In performance terms, we try to go in the other direction, rewriting regexp to use string match and regsub to use string map (well, where possible).