From: Michael Witrant Date: 2002-02-01T08:10:47+09:00 Subject: Re: Newbie question On Fri, 1 Feb 2002 06:54:09 +0900 andrew_queisser@hp.com (andrew queisser) wrote: > What's the best way to return a substring that consists of the first 4 > words, if words are comma-delimited, e.g.: > [...] > line.split(",")[0..3].join(",") > > but that can't be very efficient. I tried to do an explicit loop but I > couldn't get it any better than this: > [...] I would keep this one anyway. I don't think you can obtain much faster than that in pure Ruby, except maybe through regular expressions. But is effectiveness only a matter of speed? It's much more readable and maintainable than a loop. It expresses almost exactly what you want. If speed is really an issue, then write this part in a C extension, if possible. Or wait for a magic regexp. Mike.