Clojure – Strings replace

Clojure strings replace

In this guide, we will discuss Clojure Strings replace. Replaces all instance of a match in a string with the replacement string.

Syntax

Following is the syntax.

(replace str match replacement)

Parameters − ‘str’ is the input string. ‘match’ is the pattern which will be used for the matching process. ‘replacement’ will be the string which will be replaced for each pattern match.

Return Value − The string which has the replaced value as per the pattern match.

Example

Following is an example of replace in Clojure.

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (clojure.string/replace "The tutorial is about Groovy" #"Groovy"
      "Clojure")))
(hello-world)

Output

The above program produces the following output.

The tutorial is about clojure

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply