Page 6 Publishing's New Atari User Magazine Issue 80

Page 31

Llz~ , R~

Z^:~~,

PROGRAMMING

TtITt

FOR ATARI BASIC

ne of the most useful commands that Turbo BASIC has which is sadly missing from Atari BASIC is INSTRING, a command which locates the position of a small string within a larger string. The routine presented here works in exactly the same way as Turbos INSTRING command returning the starting position of the smaller string or a zero if no match is found.

O

USING THE ROUTINE The routine is called using the USR command as follows....

X=USR(ADR(IN$),ADR(MAIN$),LEN (MAIN$),ADR(SUB$),LEN(SUB$)) The routine finds the starting position of the smaller SUB$ within the larger MAIN$ where the starting position is returned to BASIC via the variable "X". IN$ is of course the machine code routine itself. To clarify the use of the routine by an example, consider the following....

by John Foskett

MAIN$="I LOVE MY ATARI CLASSIC SUB$="ATARI" In the above USR call, 'X' would equal 11 because the word ATARI begins with the eleventh character in MAIN$. But if SUB$="8-BIT', then "X' would equal zero because no match is found since "8 BIT' does not appear In MAIN$.

LIMITATIONS The only limitation with the routine is that SUB$ must be no more than 256 bytes in length, but MAIN$ can be of any length. This limitation Is not a problem In practice because SUB$ would rarely consist of more than a dozen characters or so and therefore there would be no real advantage In accommodating a greater length.

Page 6's New Atari User

31


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.