start, end, ... = PatternFindStrDirect(s$, pat$[, start, encoding])
s$
according to the pattern specified
in pat$
. If there is a match, the indices of where the match starts and ends in
the source string are returned together with all strings that have been captured.
If there is no match, PatternFindStrDirect()
will return -1. The optional argument
start
can be used to specify a character index inside s$
where searching should begin.
This defaults to 0 which means PatternFindStrDirect()
should start at the beginning
of s$
.
This function does pretty much the same as PatternFindStr() but
does not require you to use a generic For statement. Instead, all captures
are returned along with the start and end indices. Keep in mind, though, that PatternFindStrDirect()
does not operate inside a generic For loop, so only the first occurrence of
pat$
inside s$
will be handled of course.
If you do not need the start and end indices, you can also use the PatternFindStrShort() function instead. See PatternFindStrShort for details.
The pattern specified in pat$
must adhere to the pattern syntax as described in the
documentation of the PatternReplaceStr() function.
See PatternReplaceStr for details.
The optional encoding
parameter can be used to set the character encoding
to use. This defaults to the default string encoding set using SetDefaultEncoding().
See Character encodings for details.
s$
or -1 for no matchs$
DebugPrint(PatternFindStrDirect("Name=Andreas", "(%w+)=(%w+)"))The above example returns the strings next to the equal sign and the range 0 to 11 which describes the complete source string.