- Clojure Tutorial
- Clojure - Home
- Clojure - Overview
- Clojure - Environment
- Clojure - Basic Syntax
- Clojure - REPL
- Clojure - Data Types
- Clojure - Variables
- Clojure - Operators
- Clojure - Loops
- Clojure - Decision Making
- Clojure - Functions
- Clojure - Numbers
- Clojure - Recursion
- Clojure - File I/O
- Clojure - Strings
- Clojure - Lists
- Clojure - Sets
- Clojure - Vectors
- Clojure - Maps
- Clojure - Namespaces
- Clojure - Exception Handling
- Clojure - Sequences
- Clojure - Regular Expressions
- Clojure - Predicates
- Clojure - Destructuring
- Clojure - Date & Time
- Clojure - Atoms
- Clojure - Metadata
- Clojure - StructMaps
- Clojure - Agents
- Clojure - Watchers
- Clojure - Macros
- Clojure - Reference Values
- Clojure - Databases
- Clojure - Java Interface
- Clojure - Concurrent Programming
- Clojure - Applications
- Clojure - Automated Testing
- Clojure - Libraries
- Clojure Useful Resources
- Clojure - Quick Guide
- Clojure - Useful Resources
- Clojure - Discussion
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
clojure_strings.htm
Advertisements