S$
-----.
ISITlulvlwlx/YIzl
STRINGS
CONCATENATING STRINGS
Recall that when creating strings the
PET
will
accept alphabetic, graphie.
and numeric characters. or combinations of these,
While
handling strings,
it
may
be
useful to connect one or more strings together into a single string by linking
them end to end in a chain-like fashion:
String
1
String
2
String
'3
String
41
...
__
S_t_ri_ng_1
_ ......
__
S_tr_in_g_2_
......
i.o-_S_t_ri_ng_3_
....
Suppose. for example.
we
want
to create one large string,
Z$,
containing the
alphabet A through
Z.
By linking together the
la
st character of A$, shown below,
with
the first character of J$. and the last character of
J$
to the first character of
S$,
Z$ may
be
created:
A$
J$
~---
IAIslcloIEIFIGIHIC'P!KILlMlNlolploIRI
z$IAISlcloIEIFIGIHIIIJIKILIMINlolploIRlsITluIVlWlXlylzl
Concatenating alphabetic strings. such a A$,
J$
and
S$,
may
be
done using
one simple statement:
Z$=A$+J$+S$
The
arithmetic
operator
"+"
adds
the
contents
of
numeric
variables
or
the
numbers
themselves.
But
when
used
with
strings
the
"+"
serves
as a
linkage
sign
to
concatenate
the
strings
together.
Table
5-1
summarizes the ad-
dition of strings and numbers.
A
word
of
caution:
strings
cannot
be
separated
or
broken
apart
in
the
same
fashion as
they
are
concatenated;
they
cannot
be
"subtracted"
the
way
they
are
"added."
For
instance, to create string X$ containing the contents
of J$ and
S$
from our original strings A$, J$,
S$,
and
Z$,
it would
be
incorrect to
type:
X$=Z$-A$
Incorrect
180