Elisp: 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 Elisp: Print, Output]
number to decimal.
number to octal notation.
number to hexadecimal notation.
like %x, but uses upper case.
number to exponential notation.
number to decimal-point notation.
number to exponential notation or decimal-point notation, whichever uses fewer characters.
integer (Codepoint (Character ID)) to character.
any lisp object to lisp syntax (using prin1). [see Elisp: Print, Output]


Emacs Lisp String