
Sara Kenedy wrote:
Hi all,
I want to write a function to separate a string into a list of strings separated by commas.
Example: separate :: String -> [String]
separate "Haskell, Haskell, and Haskell" = ["Haskell", "Haskell", "and Haskell"]
If anyone has some ideas, please share with me. Thanks. Here is a solution using the Posix regex module.
Prelude Text.Regex> splitRegex (mkRegex "[ \t]*,[ \t]*") "Haskell, Haskell, and Haskell" ["Haskell","Haskell","and Haskell"] This form should work regardless of locale, but appears to be broken, although I expect this is either my fault or that of the underlying Posix library: Prelude Text.Regex> splitRegex (mkRegex "[:space:]*,[:space:]*") "Haskell, Haskell, and Haskell" ["Haskell"," Haskell"," and Haskell"]