lua-users home
lua-l archive

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


Ben <thebassplayer@gmail.com> writes:

> 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.

Though in many cases, you don't really need split, e.g. something like
the following is actually cleaner than doing a split and iterating over
the resulting table:

   for field in string.gmatch (STRING, "[^ \t\n]+") do
     .... use field ...
   end

-miles

-- 
The key to happiness
 is having dreams.	[from a fortune cookie]