EasyManua.ls Logo

Commodore VIC-20 - Page 135

Commodore VIC-20
404 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...
Chapter
4:
Advanced
BASIC
Programming 121
40
Ll$=STR'(Q)
50W'=T$+Q'
••
----
Create new string
W$
60
PRINT
"W$=
RUN
101:$=
12345
67890
Why are there blanks before the I and
61
The T$ and
Q$
string were
originally positive numeric variables T and
Q.
When T and Q were con-
verted from numbers into strings, the blank sign positions were transferred
along with the numbers.
T$
L..;....
____
.....I
Therefore, when T$ and Q$ are concatenated, the new string
W$
contains a
first-digit blank, and
an
embedded blank before the first digit
of
Q$.
T$ + Q$ =
W$
1"11121314151
1,,16171819101
Ibll1213141511>16171819101
To get rid of the blanks, go back to the separate strings T$ and
Q$.
Look again
at
the contents
of
T$ and Q$ above. The only values
we
want in
W$
are the numbers to the right
of
the sign value in both T$ and Q$. With
the LEFT$, MID$, and RIGHT$ commands, you can select any character
or
group
of
characters from within a given string.
We
want all the characters
to the right
ofthe
first character, which
is
the sign value (either blank
or-).
T$ = MID$(T$,2) does the trick.
Before: After:
Since the first digit needed
is
in the second position
of
the string, the
VIC
20
is
instructed to use only the values starting in the second position.
We
can concatenate T$ and
Q$
and drop the leading blanks all in one
statement.

Other manuals for Commodore VIC-20

Related product manuals