Clojure - Split String without loosing the separator

clojure string to int
clojure regex
clojure concat strings
clojure split string on newline
clojure string length
clojure list of characters to string
clojure map
# in clojure

Does Clojure have a Split function that splits the String into sub-strings including the separator? Like "a=b", separator "=" return: "a", "=", 'b". thanks!

i find regexp to be the simplest variant:

user> (re-seq #"[^=]+|=" "asd=dfg=hgf=jjj")
;;=> ("asd" "=" "dfg" "=" "hgf" "=" "jjj")

user> (re-seq #"[^=]+|=" "asd=dfg=hgf=")
;;=> ("asd" "=" "dfg" "=" "hgf" "=")

user> (re-seq #"[^=]+|=" "=dfg=hgf=dffff")
;;=> ("=" "dfg" "=" "hgf" "=" "dffff")

string: Clojure - Split String without loosing the separator, Does Clojure have a Split function that splits the String into sub-strings including the separator?Like. Parameters− ‘str’ is the string which needs to be split. ‘reg’ is the regular expression based on which the string split needs to happen. Return Value− The split string.

Not that I'm aware of, but you can accomplish that using interpose:

user=> (def mystring "a=b=cde=fg=hij")
#'user/mystring
user=> (interpose "=" (clojure.string/split mystring #"="))
("a" "=" "b" "=" "cde" "=" "fg" "=" "hij")

split - clojure.string, Splits string on a regular expression. Optional argument limit is the maximum number of splits. Not lazy. Returns vector of the splits. © Rich Hickey. All rights  clojure.string Available since 1.2 (split s re) (split s re limit) Splits string on a regular expression. Optional argument limit is the maximum number of splits. Not

split-with mostly does this, although it will require a little work on your part.

(split-with #(not= \= %) "a=b")

Yields

[(\a) (\= \b)] 

The most idiomatic thing I could think of to remedy this was:

(->> "a=b=c=d" ; Thread the string through the last argument of...
     (split-with #(not= \= %)) ; Splitting on =
     (flatten) ; Then flattening
     (map str)) ; And turning the characters into strings

("a" "=" "b" "=" "c" "=" "d")

This probably won't be performant because of flatten, so this won't be practical if this is called constantly on long lists.

split-with - clojure.core, There's no such guarantee for the right side! user=> (split-with odd? [1 3 5 6 7 9]) [(1 3 5) (6 7 9)] ;; Except if your predicate never returns false. user=> (split-with  Converts string to all upper-case. 8: join. Returns a string of all elements in collection, as returned by (seq collection), separated by an optional separator. 9: split. Splits string on a regular expression. 10: split-lines. Split strings is based on the escape characters or \r . 11: reverse. Reverses the characters in a string. 12: replace

(defn split-but-keep 
  "Sep  must be escaped str (er, double escaped actually).
  Use `|` separated seps for multiple e.g. \\(|\\)  as a str for open or close paren"
  [s sep]                                
  (let [re (re-pattern (str "[^" sep "]+|" sep))]
    (re-seq re s)))

This is just @leetwinski's answer

1. Primitive Data - Clojure Cookbook [Book], def data-delimiters # "[ :-]" ) ;; No-limit split on any delimiter ( clojure.string/split need to parse them with BigInteger or BigDecimal to avoid losing precision. Split a string without separator. Ask Question Asked 8 years, 9 months ago. Active 7 months ago. Viewed 5k times 3. 0. I have a string variable with value

4. Local I/O - Clojure Cookbook [Book], The built-in function clojure.java.io/writer is a versatile constructor for output streams: the REPL and its associated console I/O in a separate JVM process from your application code. You must specify the delimiters using chars, not strings, though: Get unlimited access to books, videos, and live training; Never lose your  1 Clojure - Split String without loosing the separator Jan 13 '17 1 IE not loading CSS sheet, HTML5 and html5shiv not helping Aug 31 '15 0 Lisp- modifying a local variable inside multiple statements on a function Mar 14 '16

[PDF] Clojure Cookbook, Clojure is no exception, and despite a few differences, Clojure provides the same First, Clojure strings are backed by Java's UTF-16 strings. You don't need to add com‐ ments to files to indicate string encoding or worry about losing characters in translation. (clojure.string/split "2013-04-05 14:39" data-delimiters 1). © Rich Hickey. All rights reserved. Eclipse Public License 1.0. Brought to you by Zachary Kim.. Tweet

Functional Design in Clojure, Each week, we discuss a different topic about Clojure and functional programming. That's not not a guy who likes strings. Just because you distill, doesn't mean you want to lose essence. Separate functions that “lift” the data from functions that operate at the same level of (25:50) Separating logic from side effects. Returns a vector of [(take n coll) (drop n coll)] © Rich Hickey. All rights reserved. Eclipse Public License 1.0. Brought to you by Zachary Kim.