テキスト行の正規化
Posted feedbacks - Common Lisp
なんのひねりも無いのですが、とりあえず…
(pad "○○○○
○○○○○○○
○○○○○
" #\☆)
;=> "○○○○☆☆☆
○○○○○○○
☆☆☆☆☆☆☆
○○○○○☆☆
"
(pad "○○○○
○○○○○○○
○○○○○
" #\☆)
;=> "○○○○☆☆☆
○○○○○○○
☆☆☆☆☆☆☆
○○○○○☆☆
"
1 2 3 4 5 6 7 8 9 10 | (defun pad (string &optional (padchar #\Space))
(with-output-to-string (out)
(with-input-from-string (in string)
(loop :for line := (read-line in nil) :while line
:maximize (length line) :into maxlen
:collect line :into lines
:finally (dolist (line lines)
(let ((base (make-string maxlen
:initial-element padchar)))
(format out "~A~%" (replace base line))))))))
|


nobsun
#8204()
Rating2/4=0.50
[ reply ]