Changes for clojure.string/split

jafingerhut on Fri, 16 Dec 2011
(use '[clojure.string :only (split triml)])

;; Splitting on whitespace is a common desire.
user=> (split "Some words to split" #"\s+")
["Some" "words" "to" "split"]

;; By using the pattern #"\s+", we split on all occurrences of one or
;; more consecutive whitespace characters.
user=> (split "Some    words   with\tother whitespace      \n" #"\s+")
["Some" "words" "with" "other" "whitespace"]

;; If you are used to Perl's special behavior of split(' ', $str),
;; where it ignores leading whitespace in the string to be split, this
;; does not quite do it.
user=> (split "   Leading whitespace causes empty first string" #"\s+")
["" "Leading" "whitespace" "causes" "empty" "first" "string"]

;; This will do it.
user=> (defn perl-split-on-space [s]
         (split (triml s) #"\s+"))
#'user/perl-split-on-space
user=> (perl-split-on-space "   This is often what you want   ")
["This" "is" "often" "what" "you" "want"]

;; There might be cases where you want this instead.
user=> (split "Some    words   with\tother whitespace      \n" #"\s")
["Some" "" "" "" "words" "" "" "with" "other" "whitespace"]
jafingerhut on Fri, 16 Dec 2011
(use '[clojure.string :only (split replace-first triml)])

;; Splitting on whitespace is a common desire.
user=> (split "Some words to split" #"\s+")
["Some" "words" "to" "split"]

;; By using the pattern #"\s+", we split on all occurrences of one or
;; more consecutive whitespace characters.
user=> (split "Some    words   with\tother whitespace      \n" #"\s+")
["Some" "words" "with" "other" "whitespace"]

;; If you are used to Perl's special behavior of split(' ', $str),
;; where it ignores leading whitespace in the string to be split, this
;; does not quite do it.
user=> (split "   Leading whitespace causes empty first string" #"\s+")
["" "Leading" "whitespace" "causes" "empty" "first" "string"]

;; This will do it.
user=> (defn perl-split-on-space [s]
         (split (triml s) #"\s+"))
#'user/perl-split-on-space
user=> (perl-split-on-space "   This is often what you want   ")
["This" "is" "often" "what" "you" "want"]

;; There might be cases where you want this instead.
user=> (split "Some    words   with\tother whitespace      \n" #"\s")
["Some" "" "" "" "words" "" "" "with" "other" "whitespace"]
jafingerhut on Wed, 14 Dec 2011
(use '[clojure.string :only (split replace-first)])

;; Splitting on whitespace is a common desire.
user=> (split "Some words to split" #"\s+")
["Some" "words" "to" "split"]

;; By using the pattern #"\s+", we split on all occurrences of one or
;; more consecutive whitespace characters.
user=> (split "Some    words   with\tother whitespace      \n" #"\s+")
["Some" "words" "with" "other" "whitespace"]

;; If you are used to Perl's special behavior of split(' ', $str),
;; where it ignores leading whitespace in the string to be split, this
;; does not quite do it.
user=> (split "   Leading whitespace causes empty first string" #"\s+")
["" "Leading" "whitespace" "causes" "empty" "first" "string"]

;; This will do it.
user=> (defn perl-split-on-space [s]
         (split (replace-first s #"^\s+" "") #"\s+"))
#'user/perl-split-on-space
user=> (perl-split-on-space "   This is often what you want   ")
["This" "is" "often" "what" "you" "want"]

;; There might be cases where you want this instead.
user=> (split "Some    words   with\tother whitespace      \n" #"\s")
["Some" "" "" "" "words" "" "" "with" "other" "whitespace"]
jafingerhut on Wed, 14 Dec 2011
(use '[clojure.string :only (join split replace-first)])

;; Splitting on whitespace is a common desire.
user=> (split "Some words to split" #"\s+")
["Some" "words" "to" "split"]

;; By using the pattern #"\s+", we split on all occurrences of one or
;; more consecutive whitespace characters.
user=> (split "Some    words   with\tother whitespace      \n" #"\s+")
["Some" "words" "with" "other" "whitespace"]

;; If you are used to Perl's special behavior of split(' ', $str),
;; where it ignores leading whitespace in the string to be split, this
;; does not quite do it.
user=> (split "   Leading whitespace causes empty first string" #"\s+")
["" "Leading" "whitespace" "causes" "empty" "first" "string"]

;; This will do it.
user=> (defn perl-split-on-space [s]
         (split (replace-first s #"^\s+" "") #"\s+"))
#'user/perl-split-on-space
user=> (perl-split-on-space "   This is often what you want   ")
["This" "is" "often" "what" "you" "want"]

;; There might be cases where you want this instead.
user=> (split "Some    words   with\tother whitespace      \n" #"\s")
["Some" "" "" "" "words" "" "" "with" "other" "whitespace"]