Version 0 of string first

Updated 2003-10-16 20:06:22

string first string1 string2 ?startIndex?

Search string2 for a sequence of characters that exactly match the characters in string1. If found, return the index of the first character in the first such match within string2. If not found, return -1. If startIndex is specified (in any of the forms accepted by the index method), then the search is constrained to start with the character in string2 specified by the index. For example,

   string first a 0a23456789abcdef 5

will return 10, but

   string first a 0123456789abcdef 11

will return -1.


Example:

   string first a 0a23456789abcdef

returns 1 (notice this is again a zero based value).

   string first "a" "0a23456789abcdef" 5

returns 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 11

returns 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?.


See also:


Tcl syntax help - Category Command