Apple II User Manual

Page of 257
    B$="BASIC FOR"+" "+A$
    PRINT B$
    BASIC FOR ROCKWELL R6500
Concatenation is especially useful if you wish to take a string apart and then put it back together
with slight modifications.  For instance:
    C$=LEFT$(B$,9)+"-"+MID$(B$,11,8)+"-"+RIGHT$(B$,5)
    PRINT C$
    BASIC FOR-ROCKWELL-R6500
VAL AND STRS FUNCTIONS
Sometimes it is desirable to convert a number to its string representation, and vice-versa.  "VAL"
and "STR$" perform these functions.
Try the following:
    STRING$="567.8"
    PRINT VAL(STRING$)
    567.8
    STRING$=STR$(3.1415)
    PRINT STRINGS$,LEFT$(STRING$,5)
    3.1415    3.14
"STR$" can be used to perform formatted I/O on numbers.  You can convert a number to a string
and then use LEFT$, RIGHT$, MID$ and concatenation to reformat the number as desired.
"STR$" can also be used to conveniently find out how many print columns a number will take.
For example:
    PRINT LEN(STR$(3.157))
    6
If you have an application in which a user is typing in a question such as "WHAT IS THE VOLUME
OF A CYLINDER OF RADIUS 5.36 FEET, OF HEIGHT 5.1 FEET?" you can use "VAL" to
extract the numeric values 5.36 and 5.1 from the question.
CHR$ FUNCTION
CHR$ is a string function which returns a one character string which contains the alphanumeric
equivalent of the argument, according so the conversion table in Appendix E.  ASC takes the first
character of a string and converts it to its ASCII decimal value.
One of the most common uses of CHR$ is to send a special character to a terminal.
    100 DIM A$(15)
    110 FOR I=1 TO 15
    120 READ A$(I)
    130 NEXT I
    120 F=0:I=1
    130 IF A$(I)<=A$(I+1) THEN 180
    140 T$=A$(I+1)
    150 A$(I+1)=A$(I)
    160 A$(I)=T$
    170 F=1
    180 I=I+1
    185 IF I<15 THEN 130
    190 IF F THEN 120
    200 FOR I=1 TO 15
    202 PRINT A$(I)
    204 NEXT I
    220 DATA AIM 65,DOG
    230 DATA CAT,R6500
    240 DATA ROCKWELL,RANDOM
    250 DATA SATURDAY,"***ANSWER***"
    260 DATA MICRO,FOO
    270 DATA COMPUTER,MED
    280 DATA NEWPORT BE-ACH,DALLAS,ANAHEIM