Here is another shot, but with different output results , this uses the functions of the regex mechanism, so it can be faster, and the interface is different because it matches keys with replacement strings. I provide this if it can be helpful to someone with a similar question.
(defn replace-map "given an input string and a hash-map, returns a new string with all keys in map found in input replaced with the value of the key" [sm] (clojure.string/replace s (re-pattern (apply str (interpose "|" (map
So the usage will be like this:
(replace-map "abc" {"a" "c" "b" "l" "c" "j"})
=> "clj"
bmillare
source share