To Eliminate Blank Spaces When Using Strings in a Line of Text

See all articles from Sinc-Link v4 n4
Publication: Sinc-Link
Pub Details: Sinc-Link v4 n4 (Volume 4, Issue 4)
Date: August/September 1986
Pages: 2

When an array is created to hold data the length of each string is fixed. When the array is printed the whole string will be printed even though the string is only partially filled. To demonstrate try this:

10 DIM A$(1,8)
20 LET A$(1)=" MARCH"
30 PRINT "a";A$;"a"

You will see many spaces between the word MARCH and the last “a”. The subroutine below, when called up just prior to printout, chops off the unwanted spaces at the end of the string that is being called up.

90 DIM A$(12,8)
100 INPUT X
110 GOSUB 6000
120 PRINT A$(X, TO A); "is the month of your
birthday"
130 STOP
1000 FOR A= LEN A$(X) TO 1 STEP-1
1010 IF A$(X,A) " " THEN RETURN
1020 NEXT A
1030 RETURN
2000 LET A$(1)= "JANUARY"
2010 LET A6(2)= "FEBRUARY"
2020 LET A$(3)= "MARCH"

etc

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.