Clojure-strings-replace

提供:Dev Guides
2020年6月22日 (月) 22:43時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

Clojure-文字列の置換

文字列内の一致のすべてのインスタンスを置換文字列で置き換えます。

構文

構文は次のとおりです。

(replace str match replacement)

パラメータ-「str」は入力文字列です。 「一致」は、一致プロセスに使用されるパターンです。 「置換」は、パターンマッチごとに置換される文字列です。

戻り値-パターンマッチごとに置き換えられた値を持つ文字列。

Clojureでの置き換えの例を次に示します。

(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