Clojure - Strings split



Splits string on a regular expression.

Syntax

Following is the syntax.

(split str reg)

Parameters − ‘str’ is the string which needs to be split. ‘reg’ is the regular expression based on which the string split needs to happen.

Return Value − The split string.

Example

Following is an example of split in Clojure.

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

Output

The above program produces the following output.

[Hello World]

Note that in the above output, both the strings “Hello” and “World” are separate strings.

clojure_strings.htm
Advertisements