Message from discussion Splitting a string on a character...
Received: by 10.68.223.72 with SMTP id qs8mr41630pbc.8.1352951138318;
Wed, 14 Nov 2012 19:45:38 -0800 (PST)
From: "WJ" <w_a_x_...@yahoo.com>
Subject: Re: Splitting a string on a character...
Date: 15 Nov 2012 03:45:08 GMT
Organization: NewsGuy - Unlimited Usenet $19.95
X-Antivirus: avast! (VPS 121114-1, 11/14/2012), Outbound message
Content-Type: text/plain; charset=iso-8859-1
Thomas F. Burdick wrote:
> Cory Spencer <cspen...@interchange.ubc.ca> writes:
> > Just a quickie question - is there already a Common Lisp function that
> > will split a string on a given character?
> No. Personally, I'm glad. All the functions that deal with sequences
> let you specify :start and :end, and we have POSITION. Which all add
> up to a more reasonable, less garbage-y way of doing things. You can
> see more of my thoughts on the matter here:
Wow! You mean that CL is so powerful that it enables one to roll
his own split function? Gee whiz! It's like a Turing Machine or
assembly language! No wonder you're glad! I wish I had a language
like that: one that makes you continually reinvent the wheel!
Harald Hanche-Olsen wrote:
> (defun split (thing sequence)
> (loop for start = 0 then (1+ end)
> for end = (position thing sequence :start start)
> collect (subseq sequence start end)
> while end))
user=> (clojure.string/split "eeny,meeny , miney, mo" #"[, ]+")
["eeny" "meeny" "miney" "mo"]
Say we want to stop splitting after we have 3 items:
user=> (clojure.string/split "eeny,meeny , miney, mo" #"[, ]+" 3)
["eeny" "meeny" "miney, mo"]