Cuerdas demo

This page is a live demo of The missing clojure(script) string manipulation library.

This page is live and interactive powered by the klipse plugin:

  1. Live: The code is executed in your browser
  2. Interactive: You can modify the code and it is evaluated as you type

Require the cool lib cuerdas


(ns my.ns
  (:require [cuerdas.core :as str]))

Playing with format

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"})