Clojure - 字串替換



用替換字串替換字串中所有匹配項的例項。

語法

以下是語法。

(replace str match replacement)

引數 - ‘str’ 是輸入字串。 ‘match’ 是用於匹配過程的模式。 ‘replacement’ 將是每個模式匹配將被替換的字串。

返回值 - 根據模式匹配替換值的字串。

示例

以下是 Clojure 中 replace 的示例。

(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
clojure_strings.htm
廣告

© . All rights reserved.