[Coco] INSTR question

Salvador Garcia salvadorgarciav at yahoo.com
Thu Feb 9 16:47:57 EST 2017


While there is no logic to returning the start position if no target is given, it is not a bug. It is, however, totally misleading because the start position is a valid return value, a false positive, if you will :-)  Salvador

      From: Allen Huffman <alsplace at pobox.com>
 To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com> 
 Sent: Thursday, February 9, 2017 3:42 PM
 Subject: Re: [Coco] INSTR question
   
> On Feb 9, 2017, at 3:12 PM, Allen Huffman <alsplace at pobox.com> wrote:
> ...
> Here's a head scratcher that maybe someone can explain or confirm it's a bug:
> 
> INSTR(position, search-string, target)
> * Position is optional.
> ......but I noticed today it finds the empty string: ""
> 
> PRINT INSTR("ABCDE", "")
> 1
> 
> That seems like a bug.

In Extended Color BASIC unravelled, the INSTR command has the following comments:

GET LENGTH OF TARGET STRING
BRANCH IF TARGET STRING = NULL

It branches there to L87D6, which appear as to load the current search position in to register B, then it returns with that. I assume position starts at 1, thus why it comes back with 1.

But, at 87BC is the CLRB and "MATCH ADDRESS = 0" comment. As a quick test, I ran the ROM TO RAM 64K program to copy the BASIC ROMS in to RAM, and moved the branch down three bytes so it goes to the clrb instead of the existing point:

POKE &H87B9,31

Now I think it's closer:

PRINT INSTR("ABC", "B")
2

PRINT INSTR("ABC", "")
0

...but there is not note in the comments about this being a bug, so maybe I am misunderstanding it.

What does INSTR do on other systems?

        -- A



-- 
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco


   


More information about the Coco mailing list