A FindString Problem

Just starting out? Need help? Post your questions and find answers here.
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

A FindString Problem

Post 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
PB 5.72 (32-bit) on Win 10.
User avatar
skywalk
Addict
Addict
Posts: 4215
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: A FindString Problem

Post by skywalk »

You are missing the startposition in your call. :wink:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: A FindString Problem

Post 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
Last edited by offsides on Tue Dec 08, 2015 3:14 am, edited 1 time in total.
PB 5.72 (32-bit) on Win 10.
User avatar
skywalk
Addict
Addict
Posts: 4215
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: A FindString Problem

Post 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)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: A FindString Problem

Post 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
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: A FindString Problem

Post 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)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: A FindString Problem

Post 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
PB 5.72 (32-bit) on Win 10.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: A FindString Problem

Post 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:
ImageThe happiness is a road...
Not a destination
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: A FindString Problem

Post 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
PB 5.72 (32-bit) on Win 10.
Post Reply