Clojure-strings-split

提供:Dev Guides
移動先:案内検索

Clojure-文字列の分割

正規表現で文字列を分割します。

構文

構文は次のとおりです。

(split str reg)

パラメータ-「str」は分割する必要がある文字列です。 「reg」は、文字列の分割が発生する必要のある正規表現です。

戻り値-分割文字列。

Clojureでの分割の例を次に示します。

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (clojure.string/split "Hello World" #" ")))
(hello-world)

出力

上記のプログラムは、次の出力を生成します。

[Hello World]

上記の出力では、文字列「Hello」と「World」の両方が別個の文字列であることに注意してください。