The following is an example of a program that performs this conversion.
100 OPEN #1: NAME "a:space.txt" ! input file
110 OPEN #2: NAME "a:comma.txt" ! output file
120 ERASE #2
130 LINE INPUT #1:s$
140 DO WHILE s$<>""
150 WHEN EXCEPTION IN
160 LINE INPUT #1 : t$
! t$ is the next line
170 USE
180 LET t$=""
190 END WHEN
200 LET s$=RTRIM$(s$)
! Eliminate blank characters at the right end.
210 LET p=1
220 DO WHILE s$(p:p)<>""
230 DO UNTIL s$(p:p)<>"
"
240 LET p=p+1
! Find the first non-blank
250 LOOP
260 DO UNTIL s$(p:p)=" " OR
s$(p:p)=""
270 LET p=p+1
! Find the next blank or end of the line
280 LOOP
300 LET
s$(p:p-1)="," ! insert a comma.
310 LET p=p+1
320 END IF
330 LOOP
340 PRINT #2:s$
350 LET s$=t$
360 LOOP
370 CLOSE #1
380 CLOSE #2
390 END