Strip comments from a string: Difference between revisions

Strip comments from a string in BASIC256
(Strip comments from a string in QBASIC)
(Strip comments from a string in BASIC256)
Line 514:
"apples, pears"
" apples, pears"</pre>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="freebasic">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</syntaxhighlight>
{{out}}
<pre>apples, pears # and bananas => Length = 27
apples, pears ; and bananas => Length = 27
# this is a comment => Length = 19
# this is a comment with leading whitespace => Length = 45</pre>
 
=={{header|BQN}}==
2,122

edits