[back]

Split on Character

Implement the function

val split_on_char : char -> string -> string list

so that split_on_char sep s is the list of all (possibly empty) substrings of s that are delimited by the character sep. If s is empty, the result is the singleton list [""].

Examples

let _ = assert (split_on_char ' ' "foo bar baz" = ["foo"; "bar"; "baz"])
let _ = assert (split_on_char ',' "a,,b" = ["a"; ""; "b"])
let _ = assert (split_on_char ',' "" = [""])