如何在 Haskell 中拆分字符串? [英] How to split a string in Haskell?
本文介绍了如何在 Haskell 中拆分字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Haskell 中是否有标准的方法来拆分字符串?
Is there a standard way to split a string in Haskell?
lines
和 words
在空格或换行符上分割效果很好,但肯定有一种标准的方法来分割逗号吗?
lines
and words
work great from splitting on a space or newline, but surely there is a standard way to split on a comma?
我在 Hoogle 上找不到.
I couldn't find it on Hoogle.
具体来说,我正在寻找 split "," "my,comma,separated,list"
返回 ["my","comma","separated" 的内容,"list"]
.
To be specific, I'm looking for something where split "," "my,comma,separated,list"
returns ["my","comma","separated","list"]
.
推荐答案
有一个名为 拆分.
cabal install split
像这样使用它:
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屋!
查看全文