This function finds a string pattern find$ within another string within$ starting from position StartPos, and returns an integer corresponding to the starting position of find$ in within$. This function allows the wildcard characters "*" and "?".

Users seeking the functionality of MS Excel's Search function (case-insensitivity, wildcard support) can use MatchBegin. See Syntax, below.


int MatchBegin(within$, find$ [, StartPos, Case])

NOTE: Order of string arguments is reverse of MS Excel's Search and Find functions.



is the containing string.


is the string pattern you want to find.


[optional] integer that specifies the position of the character at which to start the search. The default value is 1, which means to search from the first character.


[optional] integer that specifies whether the function is case sensitive or not. The default value is 0 or false, which means the function is not case sensitive unless Case is set to 1.


If the string pattern has been found, return the starting position of the string pattern.

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

Note 1: When using wildcards ? and *, MatchBegin returns the index for the first non-wildcard character (see second Example, below).

Note 2: MatchBegin does not support searches for raw characters ? or *. To search a string for ? or *, use the Search function (which does not support wildcards).


string str1$ = "From:";
string str2$ = "From*@";
int position = MatchBegin(str1$,str2$,1);
position = ; //should return 1
int position = MatchBegin("search inside this string","?in");
position=; //should return 8

See Also

MatchEnd, Search, Find