How to split a string in Haskell?

后端 未结 13 1590
日久生厌
日久生厌 2020-11-28 03:08

Is there a standard way to split a string in Haskell?

lines and words work great from splitting on a space or newline, but surely there is

13条回答
  •  死守一世寂寞
    2020-11-28 03:56

    There is a package for this called split.

    cabal install split
    

    Use it like this:

    ghci> import Data.List.Split
    ghci> splitOn "," "my,comma,separated,list"
    ["my","comma","separated","list"]
    

    It comes with a lot of other functions for splitting on matching delimiters or having several delimiters.

提交回复
热议问题