lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jan 2, 2008 12:41 PM, Duck <duck@roaming.ath.cx> wrote:
> Isn't this the sort of string library function which many languages offer
> under a name such as "split"? Break a string into fields separated by some
> (possibly non-trivial) pattern (default usually something like '[ \t]*')?

Yeah, that's one thing of two bigs things I miss in Lua coming from
Python, list comprehensions and the str.split method.

> If so, I would welcome the addition of a split()-like method to the
> standard string library...it strikes me as one of those 'feature creeps'
> which would be sufficiently small (given that it could reuse much existing
> matching code, as you show here) but sufficiently widely and commonly used
> as to be, well...useful.

I certainly would as well!  I would suggest the syntax be the same as
Python's:  no argument/default -> whitespace ([ \t\r\n]+), else split
by chars of each argument (Python is a 0/1 arg signature, but if
possible, it would be nice to split by more than one sequence of
chars).  Not that I'm any sort of important to be asking for library
additions.  ;)

It just springs to mind that MetaLua's extension library/utilities has
a string.split, and that alluded to pages at the Lua Users' Wiki, so I
there are some lying around.  *stops posting and looks*

Ben