Emacs Lisp: Format String

By Xah Lee. Date: . Last updated: .
(format STRING &rest OBJECTS)
Convert lisp objects into a string. It takes a input string, and several other arguments of lisp objects, and output a string.
  • The format control string may contain placeholders %c. The placeholders are replaced by argument to format.
  • Different placeholders means convert the argument to a string in particular way.
(format "Name: %s, age: %d" "jane" 25)
;; "Name: jane, age: 25"
;; decimal to hex. Returns 「a」
(format "%x" 10)
;; hexadecimal 「a」 to decimal. Returns 「10」.
(format "%d" #xa)
string. Converted by princ. [see Emacs Lisp: Print, Output]
number in decimal.
number converted to octal notation.
number converted to hexadecimal notation.
like %x, but uses upper case.
number in exponential notation.
number in decimal-point notation.
number in exponential notation or decimal-point notation, whichever uses fewer characters.
number as a single character.
any object in lisp syntax (using prin1). [see Emacs Lisp: Print, Output]

(info "(elisp) Formatting Strings")

Emacs Lisp String

Lisp Basics

Lisp Basics


Lisp Data Structure


Lisp Symbol

Lisp Misc

Working with Elisp