# $EPIC: wordtoindex.txt,v 1.2 2006/08/20 18:32:13 sthalik Exp $ ======Synopsis:====== $__wordtoindex__( ) ======Technical:====== * If the argument is omitted, the empty string is returned. * If is negative, then the value 0 is returned. * If is greater than the actual number of words in , then the return value of this function is the same as would be returned by $strlen(). * There is only one space that separates from . Any further spaces between and are part of for the purpose of counting. * The return value is the character position (as would be returned by $[[index]]() and could be used by $[[right]]() et al) of the first character in the th word in . * counts from zero! ======Practical:====== The most practical use of this function is to permit you to find the beginning position of a word in a string, especially after you have had to change the length of some of the words in the list. This technique is most obviously used by tab completion scripts which will take the input line ($L), the cursor position ($[[curpos]]()), and use the $[[indextoword]]() function to figure out where the cursor is. Then they rewrite the input line using tab completion, and use $wordtoindex() to figure out where the cursor is supposed to go after the input line has been rewritten. ======Returns:====== The number of characters before the beginning of the th word in , where counts from zero. ======Examples:====== $wordtoindex(2 foo bar blah) returns 8 $wordtoindex(999 foo bar blah) returns 12 $wordtoindex(-1 foo bar blah) returns 0