相关疑难解决方法(0)

Haskell - 是否存在替换函数?

我必须制作三个函数来替换扁平字符串和列表.

我不知道,是否有像其他语言一样的替换功能.我搜索了但不幸的是没有成功:-(

所以我的尝试还很薄.

第一功能:

replace  ::  String  ->  String  ->  String  ->  String
replace findStr replaceStr myText = replace()??
Run Code Online (Sandbox Code Playgroud)

我的第一个功能的方法:

replace :: String -> String -> String -> String
replace [] old new = []

replace str old new = loop str
  where
    loop [] = []
    loop str =
      let (prefix, rest) = splitAt n str
      in
        if old == prefix                -- found an occurrence?
        then new ++ loop rest           -- yes: replace

        else head str : loop (tail …
Run Code Online (Sandbox Code Playgroud)

haskell replace nested list

4
推荐指数
1
解决办法
4170
查看次数

标签 统计

haskell ×1

list ×1

nested ×1

replace ×1