RosettaCodeData/Task/Strip-comments-from-a-string/OCaml/strip-comments-from-a-string-2.ml
2024-10-16 18:07:41 -07:00

6 lines
190 B
Standard ML

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)