Hello All,
I'm in a big trouble with incrementation of a counter in this code. It
doesn't increment.
Could you please tell me where the problem ist and how can I solve it?
replaceBasedIdx :: String -> [String] -> String -> String
replaceBasedIdx findStr replaceStrList myText = replaceBasedIdxSub
findStr replaceStrList myText 0
replaceBasedIdxSub :: String -> [String] -> String -> Int -> String
replaceBasedIdxSub findStr replaceStrList myText counter = loop myText
where
loop [] = []
loop myText =
let (prefix, rest) = splitAt n myText
in
if findStr == prefix -- found an
occurrence?
then (replaceStrList !! (counter+1)) ++ loop rest -- yes: replace
it
else head myText : loop (tail myText) -- no: keep
looking
n = length findStr
Thank you very mutch!
Greetings!