Page 1 of 1

A FindString Problem

Posted: Tue Dec 08, 2015 2:35 am
by offsides
Why is the #PB_String_NoCase mode working as expected in ReplaceString but not FindString?

Code: Select all

S$ = "abcde"
Debug S$
Debug FindString(S$, "D", #PB_String_NoCase) ; Should be 4
Debug FindString(S$, "d", #PB_String_NoCase) ; I's 4; ok

Debug ReplaceString(S$, "D", "x", #PB_String_NoCase) ; as it should be
S$ = "abcde"
Debug ReplaceString(S$, "d", "x", #PB_String_NoCase) ; as it should be

Re: A FindString Problem

Posted: Tue Dec 08, 2015 2:44 am
by skywalk
You are missing the startposition in your call. :wink:

Re: A FindString Problem

Posted: Tue Dec 08, 2015 3:04 am
by offsides
From PB help:
The start position to begin the search. The first valid character index is 1. If this parameter isn't specified, the whole string is searched.
...so, putting a "1", say, for a start shouldn't be necessary, because I want to search the whole string, and that's the default.
The same option applies to ReplaceString, and omitting a start there works fine.

I'm sensing a minor bug, here.(?)

Skywalk, thanks for the post. Adding a start posn. is an easy fix, but not obvious.
Bill

Re: A FindString Problem

Posted: Tue Dec 08, 2015 3:12 am
by skywalk
Seriously :? You are missing an entire input parameter.

Code: Select all

S$ = "abcde"
Debug S$
Debug FindString(S$, "D", 1, #PB_String_NoCase)
Debug FindString(S$, "d", 1, #PB_String_NoCase)
Debug ReplaceString(S$, "D", "x", 1, #PB_String_NoCase)
S$ = "abcde"
Debug ReplaceString(S$, "d", "x", 1, #PB_String_NoCase)

Re: A FindString Problem

Posted: Tue Dec 08, 2015 3:44 am
by citystate
skywalk wrote:Seriously :? You are missing an entire input parameter.

Code: Select all

S$ = "abcde"
Debug S$
Debug FindString(S$, "D", 1, #PB_String_NoCase)
Debug FindString(S$, "d", 1, #PB_String_NoCase)
Debug ReplaceString(S$, "D", "x", 1, #PB_String_NoCase)
S$ = "abcde"
Debug ReplaceString(S$, "d", "x", 1, #PB_String_NoCase)
agreed

by leaving it out, the start location parameter is replaced by the flag parameter - no wonder it wasn't working

Re: A FindString Problem

Posted: Tue Dec 08, 2015 4:48 am
by TI-994A
offsides wrote:...because I want to search the whole string, and that's the default.
The same option applies to ReplaceString, and omitting a start there works fine.
Hi Bill. Both functions implement the start-position as an optional parameter, but only when the parameter after it is not utilised.

In the case of the FindString() function, in order to utilise the Mode parameter, the StartPosition parameter cannot be ignored. In your usage, the function is taking the constant value of #PB_String_NoCase, which is 1 by the way, as the start position; the mode has not been set.

Code: Select all

FindString(String$, StringToFind$ [, StartPosition [, Mode]])
The reason it worked with the ReplaceString() function is because its parameter order is different; the Mode comes before the StartPosition. So, when you set the mode, the start position is not set, and essentially retains its default value.

Code: Select all

ReplaceString(String$, StringToFind$, ReplacementString$ [, Mode [, StartPosition [, NbOccurrences]]])
Accordingly, in order to utilise the 6th parameter (number of occurrences) in the ReplaceString() function, the start position must be set first.

To maintain the default values in such cases, the #PB_Ignore directive could be used; like so:

Code: Select all

FindString(S$, "D", #PB_Ignore, #PB_String_NoCase)

Re: A FindString Problem

Posted: Tue Dec 08, 2015 5:22 am
by offsides
Ok, Skywalk, TI-994A, Citystate, it took all three of your sledgehammers to get it through my head. Thanks much for your perseverance. Seems I had a basic misunderstanding on how optional parameters were handled. Makes sense now.

Whew! :oops:

Bill

Re: A FindString Problem

Posted: Wed Dec 09, 2015 12:08 pm
by Kwai chang caine
This problem have already come several time.
They are another thread and surely several other for the same reason
The problem is often the debugger see the error when a string is waiting at the place of number or the reverse.

But this time, the two parameters can be the same type and also optional.
In the other thread Fred answering "what idea have you for fix this problem ??" But nobody have a real solution

I use this function numerous time, and again yesterday, i have missing the 1 :oops:
Each time i hurt my head, but nothing to do...
You are not alone offsides..not alone....but i know it's not a consolation :wink:

Re: A FindString Problem

Posted: Thu Dec 10, 2015 12:28 am
by offsides
Well, after the explanations I got here, especially from TI-994A, the way (and why) it works is crystal clear.
Couldn't be happier. 8)
Bill