This shows you the differences between two versions of the page.
— |
index [2007/03/02 02:32] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | # $EPIC: index.txt,v 1.2 2007/03/02 02:32:04 jnelson Exp $ | ||
+ | ======Synopsis:====== | ||
+ | $__index__(<characters> <text>) | ||
+ | |||
+ | ======Technical:====== | ||
+ | * The <characters> argument is a [[what is a word|dword]]. This is different from most functions. | ||
+ | * <characters> may contain any number of different characters. If you want to include the space character, enclose <characters> in double quotes. If you want to include the double-quote character, then put some other character before it that won't be in <text>. | ||
+ | * If the first character in <characters> is the caret ("^"), then the list of <characters> is negated; <characters> includes all characters that are NOT after the caret. | ||
+ | * Counting begins after the first space after <characters>. If multiple spaces separate <characters> and <text>, only the first such space is the separator; further spaces are part of <text> for the purpose of counting. | ||
+ | * The return value is the number of initial characters in <text> that are NOT any of the characters specified by <characters>; the position of the first instance of any character in <characters> in the string <text>, counting from zero. | ||
+ | * If none of the characters in <characters> appears in <text> (a failed search), then -1 is returned. | ||
+ | |||
+ | ======Practical:====== | ||
+ | It used to be common to use $index() to find a character in a string so | ||
+ | that you could extract the parts of the string before and after the | ||
+ | character. This is more easily done by $[[before]]() and $[[after]]() though. | ||
+ | |||
+ | ======Returns:====== | ||
+ | <file> | ||
+ | -1 no character in <characters> was found in <text> | ||
+ | > -1 index to first instance of something in <characters> in <text> | ||
+ | </file> | ||
+ | |||
+ | ======History:====== | ||
+ | This function originally appeared in ircII. | ||
+ | |||
+ | ======Examples:====== | ||
+ | <file> | ||
+ | $index(abc hello there bob) returns 12 | ||
+ | $index(abc hello there bob) returns 14 (because of the spaces after 'c' and before 'h') | ||
+ | $index(xyz hello there bob) returns -1 | ||
+ | $index() returns the empty string | ||
+ | </file> | ||
+ | |||