3.5.7.9 Find

Description

This function finds a string (find$) within another string (within$), starting from position (StartPos), and returns the starting position of find$ in within$. Unlike the Search function, the Find function is case sensitive. The Find function does not allow wildcard characters.

Syntax

int Find(string within$, string find$ [, int StartPos = 1])

NOTE: Order of string arguments is reverse of MS Excel.

Parameters

within$

is the containing string.

find$

is the string you want to find.

StartPos

specifies the position of the character at which to start the search. The default value is 1, which says "begin search from the first character."

Return

If the string has been found, return the 1-base position of the string.

If the string has not been found, return -1.

Examples

Example 1: find a substring

string str1$ = "abcde";
string str2$ = "bc";
int position = Find(str1$,str2$);
position = ; //should return 2

Example 2:

string str$="Today is a nice day";
position = Find(str$, ",");
position = ;  // should print -1 since comma(,) cannot be found
position = Find(str$, "a");
position = ;  // should print 4 as that is the first "a" in the string
//find 2nd occurance
position = Find(str$, "a", 7);// find starting from "is a ..."
position = ;  // should print 10

See Also

Search, MatchBegin, MatchEnd, FindOneOf, GetToken