SUB stripComment (s$, commentMarkers$) IF s$ = "" THEN RETURN i = INSTR(s$, commentMarkers$) IF i > 0 THEN s$ = LEFT$(s$, i - 1) s$ = LTRIM$((RTRIM$(s$))) '' removes both leading and trailing whitespace END IF END SUB DIM s$(1 TO 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 ="; LEN(s$(i)) NEXT i