Find the first occurance of a substring in a string starting at a given position. Searching begins at position start + 1, and a return value of 0 indicates no match found, otherwise the position of the first character of the search string is returned.
You might think that the start + 1 searching mechanism is odd, but it allows easy construction of enumeration loops (and is more consistent with other search routines such as database searching). For an example see the following.
i = pos(str$, "foo", 0);
while( i )do
{
do_stuff(i);
i = pos(str$, "foo", i);
}
Some examples of use might illustrate the behavior better.
pos("blahb", "a", 0) = 3
pos("blahb", "b", 0) = 1
pos("blahb", "b", 1) = 5
pos("blahb", "b", 5) = 0
pos("blahb", "la", 0) = 2
pos("blahb", "al", 0) = 0
Params
haystack$ | The string to search. |
needle$ | The substring to search for. |
start | The first character to check - 1 |
Returns
The position of the first character of needle$ in haystack$ or 0 if no match is found.