RosettaCodeData/Task/Strip-comments-from-a-string/BASIC256/strip-comments-from-a-strin...

22 lines
515 B
Plaintext

arraybase 1
dim s$(4)
s$[1] = "apples, pears # and bananas"
s$[2] = "apples, pears ; and bananas"
s$[3] = "# this is a comment"
s$[4] = " # this is a comment with leading whitespace"
for i = 1 to 4
call stripComment(s$[i], "#;")
print s$[i], " => Length = "; length(s$[i])
next i
end
subroutine stripComment(s$, commentMarkers$)
if s$ = "" then return
i = instr(s$, commentMarkers$)
if i > 0 then
s$ = left$(s$, i - 1)
s$ = trim(s$) # removes both leading and trailing whitespace
end if
end subroutine