I have already searched the website, but did not find a suitable answer to my particular question on substring replacements. I know how to replace substring/regexp via clojure.string/replace but am not sure to to utilize it in this case.
Let us say. I have some strings at first place:
(def test-str "I am a test string. :name to replace, :age to replace. And there are strange symbols in this string. And here are the keyword shall not modify, such as :not-interested.")
(def another-test-str ":nothing :to :replace")
And I have a translation table:
(def translation-table {:name "Alice"
:age 19})
I want to replace :name in test-str with "Alice", :age with 19, but do not want to replace :not-interested. The table is long, and different strings (to be replaced) contains different keywords.
Given the translation table, what is a possible systematic way of doing the substring replacement then? Namely, I want a function replace-with-translation:
(replace-with-translation test-str translation-table)
=> "I am a test string. Alice to replace, 19 to replace. And there are strange symbols in this string. And here are the keyword shall not modify, such as :not-interested."
(replace-with-translation another-test-str translation-table)
=> ":nothing :to :replace"
(replace-with-translation test-str {})
=> "I am a test string. :name to replace, :age to replace. And there are strange symbols in this string. And here are the keyword shall not modify, such as :not-interested."