Strip comments from a string: Difference between revisions

Content deleted Content added
Shuisman (talk | contribs)
Line 354: Line 354:
}</lang>
}</lang>


=={{header|BBC BASIC}}==
=={{header|ANSI BASIC}}==
<lang ansibasic>100 DECLARE EXTERNAL FUNCTION FNstripcomment$
<lang bbcbasic> marker$ = "#;"
110 LET marker$="#;"
PRINT FNstripcomment("apples, pears # and bananas", marker$)
PRINT FNstripcomment("apples, pears ; and bananas", marker$)
120 PRINT """";FNstripcomment$("apples, pears # and bananas", marker$);""""
PRINT FNstripcomment(" apples, pears ", marker$)
130 PRINT """";FNstripcomment$("apples, pears ; and bananas", marker$);""""
140 PRINT """";FNstripcomment$(" apples, pears ", marker$);""""
END
150 END
160 !
DEF FNstripcomment(text$, delim$)
170 EXTERNAL FUNCTION FNstripcomment$(text$, delim$)
LOCAL I%, D%
FOR I% = 1 TO LEN(delim$)
180 FOR I=1 TO LEN(delim$)
D% = INSTR(text$, MID$(delim$, I%, 1))
190 LET D = POS(text$, delim$(I:I))
IF D% text$ = LEFT$(text$, D%-1)
200 IF D>0 THEN LET text$ = text$(1:D-1)
NEXT I%
210 NEXT I
220 LET FNstripcomment$=RTRIM$(text$)
WHILE ASC(text$) = 32 text$ = MID$(text$,2) : ENDWHILE
230 END FUNCTION</lang>
WHILE LEFT$(text$) = " " text$ = RIGHT$(text$) : ENDWHILE
= text$</lang>


=={{header|Bracmat}}==
=={{header|Bracmat}}==