Chapter
4:
Advanced
BASIC
Programming
119
X$=Z.-AI
~.----
Incorrect
Try it yourself. Enter the values
of
AS, JS, SS,
and
XS
=
ZS-
AS
into the
VIC
20
as shown. The computer will respond with the message ?TYPE
MISMATCH
ERROR
IN LINE 50.
10
A$=/IABCDEFOHI/l
20
J,=/lJKL.MNOPQR/I
30
S,=/ISTUVWXYZ"
40
Z$=A$+JI+S$
50
X'=Z$-A.
~.---
Incorrect attempt to get J through Z string
60
PRINT
A$
RUN
?TYPE
MISMATCH
ERROR
IN
50
The correct way to extract
part
of
a larger string is
to
use string
functions. With the LEFT$, MID$,
and
RIGHT$ functions, it
is
possible to
extract any portion
of
a string. In
our
example, the letters J through Z can be
extracted as follows:
xs=
RIGHTSd A I B I c I 0 I
ElF
I G I H I I 1 J 1 K 1
LIM
I N I 0 I P
IQ
1 R I
SiT
1 u 1 v I w I x 1 viz
I,
17)
X$=I
J 1 K I L
1M
I N I 0 I
pi
Q I R I
SiT
I u I v
Iwl
x I v I z I
The
17
points to the 17th character from the right (RI G HT$) as the first
character
ofthe
string
and
includes the rest
ofthe
characters to its right. The
. string may also be built by concatenating J$ and S$.
50
X$=J$+SI
X$=IJIKILIMINlolpIQJRI+lsITlulvlwlxlvlzl
X$=IJIKILIMINIOlpIQIRISITlulvlwlxlvlzl
Numeric
StrIngs
A numeric string is a string whose contents can be evaluated as a
number. Numeric strings can be created in two different ways, each yielding
slightly different results.