[Solved] StrRFind broken

I was trying to create code to format a number for “money” (9.99) and discovered that the StrRFind function is behaving exactly like the StrFind function.

If StrRFind works the way I think is should, it should scan the string for the specified target from the right to the left, but in fact it seems to be scanning from left to right.

My test case:
Change the scene variable dotTest1: set to StrRFind(“1.11”,".") - dotTest1 = 1
Change the scene variable dotTest2: set to StrRFind(“1.111”,".") - dotTest2 = 1
Change the scene variable dotTest3: set to StrRFind(“11.111”,".") - dotTest3 = 2

I expected the following;
dotTest1 = 2
dotTest2 = 3
dotTest3 = 3

Performing the tests using StrFind returns the same results as above (which would be correct scanning from left to right, using an ordinal counting system).


But indeed the value is same as the classic strFind :confused: i’ll check in the codebase, or report if i can’t fix it myself.

Should be:
The value returned is the position, so with

For simple strFind:
1 is in position 0
. in 1
2 in 2
3 in 3

for strRFind:
3 is in position 0
2 in 1
. in 2
1 in 3

Tha value start from zero.
All expressions on the wiki.

There is a misunderstood with the expression, strRFind return the position of the lastest occurence of your term is a string.

For example:

the value return 7, because it’s the lastest “t”. In fact the description is wrong.

You wish 4 as value right ?
I ask for know what to do for have an expression like you think but we need work carefully for avoid to break the existing expression.

I found the functions but not the documentation. I was basing my logic on the InStr and InSrtRev functions from VB Excel macro code). Your www.test.com example is misleading because both strRFind and strFind will return 4 because there is a T 4 spaces (starting at 0) from either end of the string. If you change the string to “http://www.test.com” then strFind will return 11 and strRFind should return 4.
If the logic follows standard C++ protocols then all will be right in this small corner of the world.

Here you can read more things for solving your issue in GD :wink:

If the fonction was called “strLastFind”, perhaps this would help to not make a mistake.

I suppose that the ‘R’ in strRFind means REVERSE