Open haliop787 opened 4 years ago
confirmed still a bug WIN Classic 2021.10.19 & Studio 2021.09.30
This bug is still in AppGameKit IDE 2021.12.06
I would like to suggest that this gets a high priority tag. Any code that uses this to see if one string starts with the other is likely to match incorrectly.... Nasty!
X as string = "X"
Y as string = "YY"
do
print(FindString(X,Y,0,1) ) // case sensitive matches!!!
print(FindString(X,Y,1,1) ) // ignore case
Sync()
loop
a couple of work-arounds and more testing = more weirdness; see FInd2() results:
X as string = "X"
Y as string = "YY"
Z as string = "y"
do
If GetRawKeyState(27) then Exit
Print(FindString(x,y,0,1)) //original issue
Print(FindString(x,y,1,1))
Print(Find0(x,y)) //work-around
Print(Find1(x,y)) //work-around
Print(Find0(y,x)) //case sensitive
Print(Find1(y,x)) //ignore case
Print(Find0(y,z)) //case sensitive
Print(Find1(y,z)) //ignore case
Print(FindString(z,y,0,1)) //case sensitive
Print(FindString(z,y,1,1)) //ignore case
Print(FindString(z,y,0,2)) //start at 2nd char (doesn't exist)
Print(FindString(z,y,1,2)) //start at 2nd char (doesn't exist)
Print(Find2(y,z,3)) //account for start index > LEN of string //ignore case
Print(Find2(y,z,2)) // !!??
Print(Find2(y,z,1)) //
Print(Find2(y,z,0)) // ??
Sync()
loop
Function Find0(string$,find$) //case sensitive
If LEN(find$) > LEN(String$) then ExitFunction -1
Result = FindString(string$,find$,0,1)
EndFunction result
Function Find1(string$,find$) //ignore case
If LEN(find$) > LEN(String$) then ExitFunction -1
Result = FindString(string$,find$,1,1)
EndFunction result
Function Find2(string$,find$,start)
If LEN(find$) > LEN(String$) then ExitFunction -1 //work-around
If LEN(string$) < Start then ExitFunction -2 //work-around
Result = FindString(string$,find$,1,start) //ignore case
EndFunction result
result = 2? and, index 0 allowed? ...to High
Good tests. Since string operations are typically computationally expensive, especially searching, I expect the function to do the optimization of string length checking, and return false if the string being searched for is longer. I even wondered if that very optimization is simply returning true instead of false.
In the meantime, my workaround is just to append some additional spaces to ensure that the the first string is longer. Only possible when one has some idea of how long the second one is.
FindString(X+ spaces(40), Y , 0, 1) // issue #696 FindString bug
I did not bother to check if that is faster than obtaining both lengths and comparing them. I only have a couple dozen items in my array I am looping through, so in this instance, not too much of an issue. I need to look at other places where I call FindString() though.
more surprises. replace FindString() with FindStringCount() in all instances above.
reminder: Find1() & Find2() = ignore case.
is FindStringCount() completely accurate so far? (i can live with Index 0 as valid - i think case sensitive still needs testing?)
i'm getting confused :)
always returns 1 if the search length is bigger the the text length so if :
searchFor$ = "David" inText$ = "Hi"
result = findString(inText$,searchFor$,0,1)
result should be 0, as the search value was not found instead and because the search length is bigger than the Text length, returns 1.