True if s is nil, empty, or contains only whitespace.
user> (clojure.string/blank? nil) true user> (clojure.string/blank? "") true user> (clojure.string/blank? " ") true user> (clojure.string/blank? " a ") false user> (clojure.string/blank? false) true user> (clojure.string/blank? "\n") true
;; A way to remove blanks from a string. (def astr "This contains blanks \n \t \r and other whitespace") (->> astr (#(clojure.string/split % #"\s")) (remove clojure.string/blank?) (clojure.string/join " ")) ;;=> "This contains blanks and other whitespace" ;; Of course the task can be better performed other ways. ;; The goal here is just to show how blank? works. (clojure.string/replace (clojure.string/trim astr) #"\s{2,}" " ")
;; The list of the 25 whitespace chars in UTF-16. Using the \uNNNN hex code ;; when another representation is not available or not printable. ;; \u0020 is the common white space, AKA " " or '\space' as a single char. (require '[clojure.string :as s]) (s/blank? "\t \n \u000b \f \r \u001c \u001d \u001e \u001f") ;; true (s/blank? "\u0020 \u1680 \u2000 \u2001 \u2002 \u2003") ;; true (s/blank? "\u2004 \u2005 \u2006 \u2008 \u2009") ;; true (s/blank? "\u200a \u2028 \u2029 \u205f \u3000") ;; true
blank?