Link to home
Start Free TrialLog in
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
Avatar of kaufmed
kaufmed
Flag of United States of America image

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
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
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
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.