Clojure – Strings format

Clojure strings format

In this guide, we will discuss Clojure Strings format. 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

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply