EasyManua.ls Logo

Commodore Plus 4 - Page 179

Commodore Plus 4
464 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Using
tlie
String
Functions
167
The
Substring
Functions:
LEFTf,
RIGHTS,
and
MIDI
The
functions
LEFTS,
RIGHTS,
and
MIDS
can
be
used
to
form
a
substring
of
a
text
string.
Use
these
functions
to
check
input
or
to
assign
part
of
a
string
to
a
string
variable.
These
functions
are
frequently
used
in
conditional
statements.
For
example,
you
can
use
LEFTS
to
check
the
first
letter
of
the
input.
Each
of
these
functions
can
return
up
to
255
characters,
which
is
the
maximum
length
of
a
string.
If
the
substring
is
longer
than
the
master
string,
the
computer
returns
the
entire
master
string
(starting
from
the
function
starting
point).
The
parameters
for
each
function
are
enclosed
in
parentheses.
The
first
parameter
for
each
of
these
functions
is
the
master
string,
which
can
be
any
legal
string.
The
second
parameter
in
the
LEFTS
and
RIGHTS
functions
is
the
length
of
the
substring.
The
second
MIDS
parameter
is
the
starting
location
for
the
substring.
The
third
MIDS
parameter
is
the
substring
length.
The
LEFTS
substring
begins
at
the
leftmost
character
in
the
master
string
and
continues
for
the
specified
number
of
characters.
The
RIGHTS
substring
has
the
specified
length
and
ends
at
the
rightmost
character
in
the
master
string.
The
MIDS
substring
can
begin
at
any
character
position
in
the
master
string
and
continues
for
the
specified
number
of
characters.
Examples:
10Y$
=
"REDWHITEBLUE"
20
X$
=
MID$(Y$,4,5)
X$
is
the
word
WHITE.
PRINT
LEFT$("RED",4)
The
string
contains
only
RED
three
characters,
so
only
three
are
printed.
10
INPUT
"DO
YOU
WANT
TO
CONTINUE";
A$
Searches
text string
AS,
20
IP
LEFT$(A$,1>"Y"
THEN
GOSUB
70:
input
in
line
10,
for
ELSE
END
the
string
Y.
Finding
the
Length
of
a
String:
the
LEN(X$)
Function
LEN
counts
the
total
number
of
characters
in
a
text
string.
Any
text
string
can
be
counted.
Blank
spaces
and
punctuation
marks
count
as
characters
in
the
string.
For
example
"HO
HO!"
has
six
characters.
You
can
use
any
string
expression,
even
a
text-string
array element,
as
the
LEN
parameter.
The
following
example
uses
array
elements
as
string
function
parameters:
5
DIM
P$(49),L$(49)
10
F0RX=0T0
49
20
INPUT
"NEXT
NAME";L$(X)
30
FE=INSTR(L$(X),"
")

Other manuals for Commodore Plus 4

Related product manuals