Answer the question
In order to leave comments, you need to log in
How to replace a pair of characters with other pairs of characters in a string?
A string is entered, you need to replace a pair of characters in this line with another pair of characters, for example,
Such a string is "ababbbbaaa"
And replace ab with ba in Haskell
Answer the question
In order to leave comments, you need to log in
one-liner
f :: String -> String -> String -> String
f str a b = let n = length a in if take n str == a then b ++ f (drop n str) a b else if str == "" then "" else head str : f (tail str) a b
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question