Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 23, 2013 17:24
Show Gist options
  • Save shigemk2/5020573 to your computer and use it in GitHub Desktop.
Save shigemk2/5020573 to your computer and use it in GitHub Desktop.
formatを試しに使ってみる
(format "%s" "foo") ; => "foo"
;; 整数は%sまたは%dで指定する
(format "%d" 1) ; => "1"
;; 右寄せ 左寄せ 0詰め
(format "[%2d] [%-2d] [%02d]" 3 3 3) ; => "[ 3] [3 ] [03]"
;; %cは文字を文字列に変換する
(format "文字から文字列へ: %c" ?a) ; => "文字から文字列へ: a"
;; %%は%そのものを表す
(format "%d円の商品の消費税は%d%%で%d円です" 500 5 (* 500 0.05)) ; => "500円の商品の消費税は5%で25円です"
(format "%s%s" "Emacs" "Lisp") ; => "EmacsLisp"
(format "<%02d/%02d %s曜日> 降水確率 %d%%" 1 3 "金" 50) ; => "<01/03 金曜日> 降水確率 50%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment