INSTR on Commodore and other BASICs

According to The BASIC Handbook, INSTR takes three values, the starting position, source string, and pattern, in that order. According to the online C64 BASIC wiki, it takes source string, pattern and starting position in the last place.

I am trying to implement INSTR and wanted to know which is actually correct, so I went to the online PET emulator, but none of the ROMs have this function. I then looked up the 4.0 documentation, and INSTR is not mentioned.

So…

For those of you on the Commodore platform, can you tell me what version of Commodore BASIC, if any, supported INSTR?

For those of you not on the C= platforms, and your dialect has INSTR, what is the ordering of the parameters?

I found this, which mentions later Basic on Plus/4 and C128:

On the Plus/4 and C128, we can even check if one string is contained in another and at which position this occurs.

Indeed on the PET it looks like INSTR() is an array lookup - there is no INSTR function.

In BBC Basic INSTR takes either two or three parameters:

PRINT INSTR("BBC BASIC", "C") 
3
PRINT INSTR("BBC BASIC", "C", 4) 
9

GW-Basic:

https://hwiegman.home.xs4all.nl/gw-man/INSTR.html

FWIW I landed upon DEC Basic Plus manual while searching for these things: http://elvira.stacken.kth.se/rstsdoc/rsts-doc-v70/v7.0-v3-a-dec-11-orbpb-b-d_basic_plus_language_manual.pdf

So it appears both formats are found in the wild.

Simple enough, I’ll test the input types and switch.

Done like dinner!

This is an endeavor as noble as it is futile! :slight_smile:

INSTR is a feature found in Commodore BASIC 3.5 (Commodore-264 series: C16, C116, Plus/4), and Commodore BASIC 7.0 (C128). As I understand it, only the first two arguments are required (source-string and pattern, respectively), and the third argument (start position) is optional.

(In Commodore BASIC, a missing value often defaults to 0. E.g., we may write “10 GOTO” in order to jump to line #0.)

Apparently, it is also found in Commodore BASIC 4.2 (CBM 8096, CBM 8296), but here it comes with 4 arguments: pattern, variable/source-string, start position, search mode.
Search modes are: 0 = matching, left to right, 1 = difference, left to right, 2 = matching, right to left, 4 = difference, right to left. (Meaning, we can search either for matching strings or differences and this either left-to-right or in reverse order.)
Compare: BASIC – C64-Wiki

[Note/edit: This may well be where the confusion about the order of arguments originates, assuming that the 4th argument, search mode, is optional, as well, and defaults to 0, which is “normal” operations. Notably, the order in BASIC 4.2 syntax would then be: pattern, source-string, start position.]

Commodore BASIC 4+ (CBM II series, CBM 500/600/700) has INSTR as well, but this seems to follow the 2/3 arguments syntax of BASIC 3.5 and 7.0.

INSTR is definitely not found on the original PET/CBM series (BASIC 1 (or 2), 2 (or 3), 4.0) or on the VIC-20 or C64 (BASIC V. 2.0).

1 Like

I was confused by the fact that 3.5 actually post-dates 4.0. So when I saw 4.0 in the PET emulator I thought that was later than 3.5 and it would have INKEY. C’est la vie.

There are lots of reasons for getting confused by Commodore BASIC versioning! :slight_smile:
(Also, mind the edit in my last post.)

7 posts were merged into an existing topic: INKEY$ in cross-platform C

My first thought was, “There’s no INSTR in Commodore BASIC!” But then I remembered - oh yeah, I only know BASIC 2.0. Even when I did Commodore 128 BASIC programming, I stuck with BASIC 2.0 commands except for the new graphics and sound commands.

1 Like