user1280282
user1280282

Reputation: 303

Spliting a list of strings in OCaml

I have a list as let a = ["q0,x";"q1,y"]; which is of type string list.

I want to make it as [("q0","x");("q1","y")]; which is a list of (string * string) tuples.

How do I do that??

Upvotes: 0

Views: 555

Answers (1)

Çağdaş Bozman
Çağdaş Bozman

Reputation: 2540

You can use module Str and the function split :

let split = 
   List.map (fun str ->
      match Str.split (Str.regexp ",") str with
        | a :: b :: _ -> a, b
        | _ -> assert false (* should not happen *))

Upvotes: 3

Related Questions