Does OCaml have String.split function like Python?

后端 未结 4 601
离开以前
离开以前 2021-01-12 01:24

I am using this to split strings:

 let split = Str.split (Str.regexp_string \" \") in
   let tokens = split instr in
 ....

But the problem

4条回答
  •  走了就别回头了
    2021-01-12 01:38

    Using Jane Street's Core library, you can do:

    let python_split x =
      String.split_on_chars ~on:[ ' ' ; '\t' ; '\n' ; '\r' ] x
      |> List.filter ~f:(fun x -> x <> "")
    ;;
    

提交回复
热议问题