This is an extension of this question: Haskell replace characters in string
I would like to tweak the following expression to replace a char with a string
let replaceO = map (\c -> if c=='O' then 'X'; else c)
In the end, I would the following results (XX can be a string of any length):
replaceO "HELLO WORLD"
"HELLXX WXXRLD"
map, take a look atconcatand consider(\c -> if c == 'O' then "X" else [c]). Notice that each character gets turned into a string instead.elemguesses then x else '-') wordmap. If you are trying to replace certain characters with a new string, then useconcatMap.