How to split a string in Haskell?

后端 未结 13 1580
日久生厌
日久生厌 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:45

    If you use Data.Text, there is splitOn:

    http://hackage.haskell.org/packages/archive/text/0.11.2.0/doc/html/Data-Text.html#v:splitOn

    This is built in the Haskell Platform.

    So for instance:

    import qualified Data.Text as T
    main = print $ T.splitOn (T.pack " ") (T.pack "this is a test")
    

    or:

    {-# LANGUAGE OverloadedStrings #-}
    
    import qualified Data.Text as T
    main = print $ T.splitOn " " "this is a test"
    

提交回复
热议问题