Searches backwards through a string expression for occurrence of a substring, optionally from a given position. If the substring is found, the position at which it begins is returned. If the substring is not found a 0 is returned.
i = RInStr(a$, b$ [,m%] [, compmode])
i = RInStr([m%], a$, b$ [, compmode])
a$, b$: sexp
m%, compmode: iexp
RInStr() searches backwards through the string expression a$ starting from position m% for the substring b$. If m% is not given the search starts from the last character in string a$. Note If m% is set to 0 (zero), GB32 acts as if it is not given and searches from the last character - this is intended behaviour and not a bug.
The compare compmode indicates how the search for b$ inside a$ is to be performed.
compmode | meaning |
---|---|
0 | binary compare (default) |
1 | case insensitive |
-2 | converts both strings to uppercase before searching |
-3 | converts both strings to lowercase before searching |
If b$="" the command returns 0.
Debug.Show
Trace RInStr("Hello GFA", "ll", 2) // prints 0
Trace RInStr("Hello GFA", "ll") // prints 3
Trace RInStr("Hello GFA", "ll", 4) // prints 3
Trace RInStr(0, "Hello GFABASIC", "LL", 1) // 3
Trace RInStr(0, "Hello GFABASIC", "LL", 0) // 0
Trace RInStr("Hello GFABASIC", "LL", 0, -2)// 3
Trace RInStr("Hello GFABASIC", "LL", 0, -3)// 3
EndsWith, FindFirstOf, FindLastOf, InStr, Left$, Mid$, Mode, Right$, StartsWith
{Created by Sjouke Hamstra; Last updated: 18/12/2022 by James Gaite}