繁体   English   中英

如何在Clean中的空格上分割字符串?

[英]How to split a string on spaces in Clean?

我是函数编程和Clean的新手。 我想在空白上拆分字符串,就像Haskell中的words函数一样。

words :: String -> [String]
input: "my separated list " 
output: ["my","separated","list"]

这是Haskell中的定义:

words :: String -> [String]
words s =  case dropWhile {-partain:Char.-}isSpace s of
             "" -> []
             s' -> w : words s''
                where (w, s'') =
                    break {-partain:Char.-}isSpace s'

但是Clean没有break ,并且我不知道它的含义以及如何在Clean中实现它:

s' -> w : words s''
where (w, s'')

正如StdEnvApi文档所建议的那样,您应该将String转换为列表以使用StdList API函数(第20页第6节)。 结果是这样的:

splitString :: String -> [String]
splitString x = [foldr (+++) "" i\\i<- splitString` (fromString x)]
    where
        splitString` :: [String] -> [[String]]
        splitString` x = let (p, n) = span ((<>) " ") x in
            if (isEmpty n) [p] [p:splitString` (tl n)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM