Clojure-strings-subs

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

Clojure-文字列サブ

「s」の部分文字列を返します。開始文字列で始まり、末尾文字列で終了します(デフォルトは文字列の長さです)。

構文

構文は次のとおりです。

(subs s start end)

パラメータ-「S」は入力文字列です。 「開始」は、サブストリングを開始するインデックス位置です。 「終了」は、サブストリングを終了するインデックス位置です。

戻り値-部分文字列。

以下は、Clojureでの文字列フォーマットの例です。

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (subs "HelloWorld" 2 5))
   (println (subs "HelloWorld" 5 7)))
(hello-world)

出力

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

llo
Wo