56
Array
Expressions
In
mathematics, a matrix
is
a group
of
arithmetic values arranged
in
a system of rows
and columns, and a vector
is
a series
of
arithmetic values arranged
in
a single row.
In
the
BASIC
language, however, a matrix
is
a one·
or
two·dimensional array
of
numeric data only. Array expressions are used
to
perform operations
on
the entire
collection of numeric or character array elements rather than on each element
individually (scalar operations).
(See
MAT
Assignment Statements, Chapter 4.)
Substring
Function
A character string
is
a sequence of characters
in
a character expression. The string
(STR) function allows you
to
extract, combine,
or
replace specific characters
in
the expression. The STR function
is
used with LET statements
to
do
the
following:
• Extract characters - For example,
in
the following statements:
10 A$
= 'PRODUCTION CONTROL'
20STR(B$,1,10) =STR(A$,1,10)
statement 20 extracts the first 10 characters from A$ and assigns them
to
the
first 10 characters of
B$.
In
statement 20, A$
is
the expression from which
characters are
to
be extracted, 1
is
the
position
of
the first character
to
be
extracted, and 10
is
the number
of
characters
to
be
extracted.
• Combine characters - For example,
in
these statements:
10 A$ = 'PRODUCTION'
20
B$
= 'CONTROL'
30
LET STR(A$, 12,7) =
B$
statement
30
places the content
of
B$
(CONTROL) with the content
of
A$
(PRODUCTION) after the 11th character, which
is
a blank.
In
statement 30,
A$
is
the expression
to
which characters
will
be included, 12
is
the first posi·
tion
to
be filled by the additional characters. and 7
is
the number of characters
to
be included.
• Replace characters - For example,
in
these statements.:
10 LET
A$=
'PART 789'
20 LET
B$
= 'PART 1234'
30
LET STR(A$,6,4) = STR(B$,6,4)
statement
30
replaces the 789
in
A$ with the 1234 from
B$.
Again,
the
numbers 6 and 4
in
statement
30
specify the first character
to
be
replaced
and the number of characters
to
be replaced, respectively. These numbers do
not have
to
be
the same on both sides
of
the equal sign.
Note
that
the length of the operand on the left
of
the equal
sign
should
be
shorter than
or
equal
to
the length of
the
operand on the right of the equal sign.
/'