RosettaCodeData/Task/Strip-comments-from-a-string/OCaml/strip-comments-from-a-string-2.ocaml
2023-07-01 13:44:08 -04:00

6 lines
190 B
Text

let strip_comments =
let print = ref true in
String.iter (function
| ';' | '#' -> print := false
| '\n' -> print_char '\n'; print := true
| c -> if !print then print_char c)