Name
ReverseFindStr -- find a substring in a string in reverse (V9.0)
Synopsis
pos = ReverseFindStr(string$, substring$[, casesen, startpos, encoding])
Function
Searches for substring$ in string$ and returns the position of the substring. In contrast to FindStr(), searching is done in reverse, i.e. from the string's end to its start.

The position is returned in characters, not in bytes, starting at position 0 for the first character. If substring$ cannot be found, -1 is returned. The optional argument casesen allows you to specify if the search should be case sensitive. This defaults to the global case sensitive default mode set using IgnoreCase(). See IgnoreCase for details.

You can also specify a starting position for the search in the optional argument startpos. This position needs to be specified in characters, not in bytes. By default, startpos is set to the length of string$ in characters minus 1.

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.

Inputs
string$
string to search in
substring$
string to find in string$
casesen
True for a case sensitive search or False for a case insensitive search; the default is True or whatever default has been set using the IgnoreCase() command
startpos
optional: starting position of the search operation in characters (defaults to the length of string$ minus 1)
encoding
optional: character encoding to use (defaults to default string encoding)
Results
pos
position of substring$ in string$ in characters or -1 if not found
Example
result = ReverseFindStr("Hello, Hello!", "Hello")
Print(result)
This will print "7" because searching is done in reverse, which is why the position of the second "Hello" is returned.

Show TOC