에서 단어의 목록을 제거하는 방법 내가 (Clojure의에서)하고 싶으면 무엇 : 예를 들어문자열
, 나는 제거해야 할 단어의 벡터가 :
(def forbidden-words [":)" "the" "." "," " " ...many more...])
을 .. . 문자열의 벡터 :
(def strings ["the movie list" "this.is.a.string" "haha :)" ...many more...])
그래서, 각각의 금지 된 단어가 각 문자열에서 제거해야하며, 그 결과는,이 경우에는 다음과 같습니다 [ "영화 목록" "thisisastring" "하하"].
어떻게 하시겠습니까? 대신
(for [s strings]
(-> s ((apply comp
(for [s forbidden-words] #(.replace %1 s ""))))))
당신이 더 많은 '관용적'싶은 경우에, 당신은 clojure.contrib.string에서 replace-str
을 사용할 수 있습니다 : 함수의 합성이 좋고 간단 할 수 ->
매크로를 사용
이 링크가 도움이 : http://github.com/richhickey/clojure-contrib/blob/bacf49256673242bb7ce09b9f5983c27163e5bfc/src/main/clojure/clojure/contrib/string.clj#L162 –