This page is live and interactive powered by the klipse plugin:
(ns my.ns
(:require [cuerdas.core :as str]))
format is a simple string formatting function.
The string formating works in two main modes: indexed and associative.
The indexed mode is the most simple and consists in using %s tokens in the string indicating the position where interpolation should be done and an arbitrary number of non associate arguments. Format will replace all %s occurrences with the provided values in ordered mode:
(str/format "hello %s and %s" "yen" "ciri")
If you don’t provide enough values, the %s tokens won’t be changed:
(str/format "hello %s and %s" "yen")
There are also the associative mode that consists in passing only one associative argument (map or vector) and use named interpolation tokens:
(str/format "hello %(name)s" {:name "yen"})
A part of the %()s syntax, the $something can be used:
(str/format "hello $name" {:name "yen"})
And you can access to indexed positions of an vector using $0, $1, $N syntax:
(str/format "hello $0" ["yen"])
You can use str/fmt as shorter alias to str/format function.
(str/fmt "hello %(name)s" {:name "yen"})