[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: split method?
- From: Etan Reisner <deryni@...>
- Date: Wed, 29 Jun 2011 14:40:34 -0400
On Wed, Jun 29, 2011 at 10:47:29AM -0700, Norbert Kiesel wrote:
> On Wed, 2011-06-29 at 11:42 +0200, Valerio Schiavoni wrote:
> > This is our split function:
> > function split(s, sep)
> > local res = {}
> > sep = sep or ' '
> > for v in s:gmatch('[^' .. sep .. ']+') do
> > res[#res + 1] = v
> > end
> > return res
> > end
>
> Would make sense to throw in an assert(#sep == 1) because this fails for
> e.g. split('hi[]there', '[]')
The problem with that is an escaping one. split('hi[]there', '%[%]') works.
But with a sep or more than one you won't necessarily get what you were
expecting since it'll split on any of the characters in sep and not on the
unit.
-Etan