Created
February 23, 2013 17:24
-
-
Save shigemk2/5020573 to your computer and use it in GitHub Desktop.
formatを試しに使ってみる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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