我想拿2个这样的清单;
find=["Hou","House","Mouse"]
repl=["Mou","Bird","House"]
所以当我给出这样的文字时;
"The House with Mouse is big"
输出应该是这样的;
"The Mouse with House is big"
所以我写了这个;
replace :: String->String->String->String
replace _ _ []=[]
replace find repl text
= if take(length find) text == find
then repl ++ replace find repl (drop (length find) text)
else [head text] ++ (replace find repl (tail text))
replaceMore ::[String]->[String]->String->String
replaceMore _ _ []=[]
replaceMore _ [] _ =[]
replaceMore [] _ _ =[]
replaceMore find repl text
= if (tail find) == [] || (tail repl)==[]
then text
else replaceMore (tail find)
(tail repl)
(replace (head find) (head repl) text)
它返回
"The Mouse with Mouse is big"
所以它不像我想要的那样工作,我认为问题就在这里;
replaceMore _ _ []=[]
replaceMore _ [] _ =[]
replaceMore [] _ _ =[]
但我仍然不知道如何解决这个问题。所以有什么想法吗?