將字符串中的匹配的所有實例替換為替換字符串。
以下是replace的基本使用語法:
(replace str match replacement)
參數(shù)? 'str'是輸入字符串。 'match'是將用于匹配過程的模式。 'replacement'將是每個模式匹配將被替換的字符串。
返回值 ? 匹配替換后的字符串。
下面是replace函數(shù)的示例:
(ns clojure.examples.hello (:gen-class)) (defn hello-world [] (println (clojure.string/replace "The tutorial is about Groovy" #"Groovy" "Clojure"))) (hello-world)
以上示例將輸出以下結果:
The tutorial is about clojure
更多建議: