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.
(format "Name: %s, age: %d"
"jane"
 25)
;; "Name: jane, age: 25"
%s
string. Converted by princ. [see Emacs Lisp: Print, Output]
%d
number in decimal.
%o
number converted to octal notation.
%x
number converted to hexadecimal notation.
%X
like %x, but uses upper case.
%e
number in exponential notation.
%f
number in decimal-point notation.
%g
number in exponential notation or decimal-point notation, whichever uses fewer characters.
%c
number as a single character.
%S
any object in lisp syntax (using prin1). [see Emacs Lisp: Print, Output]

(info "(elisp) Formatting Strings")

Emacs Lisp String

Lisp Basics

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Lisp Basics

Basics

Lisp Data Structure

Function

Lisp Symbol

Lisp Misc

Working with Elisp