Download Print this page

Radio Shack TRS-80 model III Owner's Manual page 110

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

Advertisement

DISK BASIC
llllitlt^^
search
for.
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":
INSTR(A$*
"INC")
returns a
value of
2.
INSTR
<A$> "12")
returns
a
zero.
INSTR(A$t "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"?
S$
413
INPUT "TARGET TEXT'S T*
45
CLS
50
C
=
s
P
=
1
'P
=
POSITION*
C
=
COUNT
60
F
=
INSTR<PfS*fTt)
70
IF
F
=
THEN
120
80
C
=
C
+
1
90
PRINT @0>LEFT$(S$*F-i>
+
STRING*
(
LEN(T$
)>
191
)
+
-
RIGHT* <S*>LEN<S*)-F-LEN(T*)+1>
100
P
=
F
+
LEN(T$)
110
IF
P
<=
LEN(S$)
-
LEN(T$)
+
1
THEN
S0
120
PRINT "FOUND
"5
C5
"OCCURRENCES"
109

Advertisement

loading