How to Split string in f# without taking out the caracter used to split

Viewed 60

I'm trying to take a string like "hello world : bye world" and get ["hello world"; ":" ;"bye world"].

1 Answers

This is the simplest function I can think of to pass your test case.

let split (str:string) =
    str.Split ':'
    |> Seq.collect(fun x -> [":"; x.Trim()])
    |> Seq.tail
    |> Seq.toList

split "hello world : bye world" // ["hello world"; ":"; "bye world"]
Related