Download Print this page

Radio Shack TRS-80 Owner's Manual page 127

Mini-disk operation disk operating system disk basic programming language
Hide thumbs Also See for TRS-80:

Advertisement

DISK BASIC
This
function
lets
you
search
through
a
string to
see
if
it
contains another
string.
If
it
does,
instr
returns the starting position
of
the substring
in
the target
string;
otherwise, zero
is
returned.
Note
that
the
entire
substring
must
be contained
in
the
search
string,
or zero
is
returned.
Also, note
that
instr only
finds
the
first
occurrence of a
substring
at
the position
you
specify.
Examples
In these
examples, a$
=
"Lincoln":
INBTR(A$»
"INC")
returns a
value of
2.
INSTR
(Mt
"12")
returns
a zero.
INSTR(A$» "LINCOLNABRAHAM")
returns
a
zero.
For
a
slightly different
use of instr, look
at
INSTR
(3»
"1232123"
,
"12")
which
returns
5.
Sample
Program
This
program
gets
search
and
target text
from
the
keyboard,
then
locates
all
occurrences of
the target
text in
the search
text.
Line
90
is
just for
"show."
10
CLEAR
1000
20
CLS
30
INPUT "SEARCH TEXT"
5
S$
40
INPUT "TARGET TEXT"
I
T*
45
CLS
50
C
=
:
P
=
1
'P
=
POSITION*
C
=
COUNT
G0
F
=
INSTR(P»S$»T$)
70
IF
F
=
THEN
120
80
C
=
C +
1
90
PRINT
@B»LEFT$(S$
!
F-1)
+
STRING$CLEN<
T*)
.
191
)
+
-
RIGHT* (S*»LEN(S$)-F-LEN(T*)+1)
100
P
=
F
+
LEN(T$)
110
IF
P
<=
LEN(S$)
-
LEN(T$)
+
1
-
THEN
60
120
PRINT "FOUND
"5
C!
"OCCURRENCES"
109

Advertisement

loading

This manual is also suitable for:

Model iii