Avatar of dhomaha
dhomaha
 asked on

InStrRev return value

Below is what is an example found in crystal help of the instrrev  function. How are they getting 8 ?


InStrRev ("abcdefgbchijk", "bc", -1)
Returns 8, where matching starts from the very end of the string
Programming

Avatar of undefined
Last Comment
kaufmed

8/22/2022 - Mon
kaufmed

The return value of InStrRev is the position (not index) of the first place in the string where "bc" is found. However, since you are using the "Rev" version, and not InStr, the searching starts from the end of the string, not the beginning. The net effect is that you find the last occurrence of "bc" in your target string. If you used instead InStr, then the returned value would be 2.

Position starts counting from 1; Index starts counting from 0.
ASKER CERTIFIED SOLUTION
dsacker

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mike McCracken

Agree.

Generally this is used to then select a substring so you want the starting point of the searched for string based on the beginning of the string.  If it returned the value based on the end of the string you would then have to calculate the length of the string to get the starting point for you substring.

mlmcc
kaufmed

The return value of InStrRev is the position (not index) of the first place in the string where "bc" is found.
On rereading that, I think I should make this correction for clarity:

The return value of InStrRev is the position (not index) of the last place in the string where "bc" is found.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck