How to split a string in Haskell?

后端 未结 13 1570
日久生厌
日久生厌 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 04:06

    Without importing anything a straight substitution of one character for a space, the target separator for words is a space. Something like:

    words [if c == ',' then ' ' else c|c <- "my,comma,separated,list"]
    

    or

    words let f ',' = ' '; f c = c in map f "my,comma,separated,list"
    

    You can make this into a function with parameters. You can eliminate the parameter character-to-match my matching many, like in:

     [if elem c ";,.:-+@!$#?" then ' ' else c|c <-"my,comma;separated!list"]
    
    0 讨论(0)
提交回复
热议问题