LENGTHS
OF
STRINGS
Characters
and
Strings
SuperBASIC makes
It
easy
to
find the length or number
of
characters
of
any string.
You
simply
write,
for
example:
PRINT
LENlweekday$)
••
If
the pigeon
hole,
weekday$. contains
FIRST
the number 5
will
be
displayed.
You
can
see the effect
in
a simple program
NEW
..
"
10
LET
weekday$
=
"FIRST",-"
20
PRINT
LEN(weekday$)
..
"
RUN
"'11
The screen should display:
5
LEN
is
a keyword
of
SuperBASIC.
An alternative method
of
achieving the same result uses both a string pigeon hole and
a numeric pigeon
hole.
NEW
....
"
10
LET
weekday$
::::
IIFIRST".
II
20
LET
Length;
LENlweekday$)
..
"
30
PRINT
tength
..
"
RUN.-II
The screen should display:
5
as
before,
and
two
internal pigeon holes contain the values shown:
•
•
weekdayS I FIRST I
length D
Let
us
return
to
the problem of average lengths
of
words.
Write a program
to
find the average length
of
the three words:
FIRST,
OF,
FEBRUARY
PROGRAM
DESIGN
When problems get beyond what you regard
as
very
trivial,
It
is
a good idea
to
construct
a program design before
writing the program
itself.
•
1.
Store the three words
in
pigeon
holes.
2.
Compute the lengths and store them.
3.
Compute the average.
4.
Print the
result.
NEW'-II
10
LET
weekday$
::::
"FIRST
II
"II
20
LET
word$
::::
"0F
II
'-1I
30 LET
month$
::
IIFEBRUARY"'-II
40
LET
length1
LENlweekday$)
...
50
LET
length2
;
LEN
(word$)
..
"
60
LET
Length3
;
LENlmonth$)
..
"
70
LET
sum;
length1
+
Length2
+
Length3
..
"
80
LET
ave
rage::::
sum/3.11
90
PRINT
average,-"
RUN'-II
The
symbol!
means divided
by.
The output or result
of
running the program
is
simply:
5
•
~)f
)
12/84