Basic Werk | Blog | Contact


MEMOMEM

CommonLisp_substitute-if



Common Lisp の文字列置換には substitute-if が使える。


Syntax は (substitute-if replacement predicate string)



(substitute-if #\_ (complement #'alphanumericp) "text-text-test!") ;; -> "text_text_test_"
(substitute-if #\_ #'alphanumericp "text-text-test!") ;; -> "____-____-____!"
(substitute-if #\_ #'(lambda (x) (equal x #\!)) "text-text-test!") ;; -> "text-text-test_"
(substitute-if #\_ #'digit-char-p "text1-text2-test3!") ;; -> "text_-text_-test_!"


参考:

Land of Lisp


#CommonLisp #Lisp #CLISP #substitute-if #alphanumericp #digit-char-p #complement



SN 2013/07/22 22:34:38

Archives > CommonLisp_substitute-if.html