[Coco] INSTR question

Allen Huffman alsplace at pobox.com
Thu Feb 9 16:42:23 EST 2017


> 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




More information about the Coco mailing list