RosettaCodeData/Task/Determine-if-a-string-is-squeezable/BASIC/determine-if-a-string-is-squeezable.basic
2023-07-01 13:44:08 -04:00

33 lines
1.1 KiB
Text

10 DEFINT A-Z
20 READ N: DIM S$(N): FOR I=1 TO N: READ S$(I): NEXT
30 READ S,C$: IF S=0 THEN END
40 PRINT "Character: '";C$;"'"
50 O$=S$(S): GOSUB 200
60 I$=S$(S): GOSUB 100: GOSUB 200
70 PRINT
80 GOTO 30
100 REM --
101 REM -- Squeeze I$ on character C$, output in O$
102 REM --
105 O$ = ""
110 X = INSTR(I$,C$)
120 IF X = 0 THEN O$ = O$ + I$: RETURN
130 O$ = O$ + LEFT$(I$,X)
140 FOR X=X TO LEN(I$): IF MID$(I$,X,1) = C$ THEN NEXT
150 I$ = RIGHT$(I$,LEN(I$)-X+1)
160 GOTO 110
200 REM --
201 REM -- Display O$ and its length in brackets
202 REM --
210 PRINT USING "##";LEN(O$);
220 PRINT "<<<";O$;">>>"
230 RETURN
400 REM -- Strings
410 DATA 5
415 DATA""
420 DATA"'If I were two-faced, would I be wearing this one?' --- Abraham Lincoln "
430 DATA"..1111111111111111111111111111111111111111111111111111111111111117777888"
440 DATA"I never give 'em hell, I just tell the truth, and they think it's hell. "
450 DATA" --- Harry S Truman "
500 REM -- String index and character to squeeze
510 DATA 1," ", 2,"-", 3,"7", 4,".", 5," ", 5,"-", 5,"r", 0,""