Clojure - Strings format


Advertisements

The formatting of strings can be done by the simple format function. The format function formats a string using java.lang.String.format.

Syntax

Following is the syntax.

(format fmt args)

Parameters − ‘fmt’ is the formatting which needs to be applied. ‘Args’ is the parameter to which the formatting needs to be applied.

Return Value − The return value is a string.

Example

Following is an example of the string formatting in Clojure.

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (format "Hello , %s" "World"))
   (println (format "Pad with leading zeros %06d" 1234)))
(hello-world)

Output

The above program produces the following output.

Hello , World
Pad with leading zeros 001234
clojure_strings.htm
Advertisements