Selectively replace multiple instances of a character within a string: Difference between revisions
Selectively replace multiple instances of a character within a string (view source)
Revision as of 16:57, 28 July 2022
, 1 year ago→{{header|Haskell}}
m (→Python) |
|||
Line 153:
import Data.Maybe (fromMaybe)
---------- POSITIONAL CHARACTER
nthCharsReplaced :: M.Map Char [Maybe Char] -> String -> String
Line 159:
where
go a c =
in ( M.insert c (succ i) a,
otherChar i c (fromMaybe [] (M.lookup c ruleMap))
)
else (a, c)
otherChar :: Int -> Char -> [Maybe Char] -> Char
Line 168 ⟶ 171:
| i < length deltas = fromMaybe c (deltas !! i)
| otherwise = c
--------------------------- TEST -------------------------
|