How to split string at fixed numbers of character in clojure? -
i'm new in clojure. i'm learning splitting string in various ways. i'm taking here: https://clojuredocs.org/clojure.string/split there no example split string @ fixed number of character.
let string "hello welcome here". want split string after every 4th char, output (after split) should ["hell" "o ev" "eryo" "ne w" "elco" "me t" "o he" "re"]. note white space consider char.
can tell me, how can this? thanks.
you use re-seq
:
user> (def s "hello welcome here") #'user/s user> (re-seq #".{1,4}" s) ("hell" "o ev" "eryo" "ne w" "elco" "me t" "o he" "re")
or partition string, treating seq:
user> (map (partial apply str) (partition-all 4 s)) ("hell" "o ev" "eryo" "ne w" "elco" "me t" "o he" "re")
Comments
Post a Comment