如何在Haskell中分割字符串? [英] How to split a string in Haskell?
本文介绍了如何在Haskell中分割字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
行
和 words
在分隔空格或换行符时很好用,但当然有一种标准的方式来分隔逗号?我无法在Hoogle上找到它?
具体而言,我正在寻找 split,my,comma,分隔列表
返回 [my,comma,separated,list]
感谢。
解决方案
有一个名为 split 。
cabal install split
像这样使用它:
ghci> import Data.List.Split
ghci> splitOn,,逗号,分隔,列表
[my,逗号,分隔,列表]
它具有许多其他功能,用于分割匹配分隔符或者具有多个分隔符。
Is there a standard way to split a string in Haskell?
lines
and words
work great from spliting on a space or newline, but surely there is a standard way to split on a comma? I couldn't fint it at Hoogle?
To be specific, I'm looking for something where split "," "my,comma,separated,list"
returns ["my","comma","separated","list"]
Thanks.
解决方案
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.
这篇关于如何在Haskell中分割字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文