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

22 lines
535 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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
2026-04-30 12:34:36 -04:00
call stripComment(s$[i], "#;")
print s$[i], " => Length = "; length(s$[i])
2023-07-01 11:58:00 -04:00
next i
end
subroutine stripComment(s$, commentMarkers$)
2026-04-30 12:34:36 -04:00
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
2023-07-01 11:58:00 -04:00
end subroutine