lua-users home
lua-l archive

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


thanks for the quick reply.

>>I could not find a function to split a string into a table

LHdF> Probably because there are many ways to split a string. The workhorse will be
LHdF> gsub. Here is an example from the reference manual:

LHdF> t = {n=0}
LHdF> gsub("first second word", "(%w+)", function (w) tinsert(%t, w) end)
-->> t={"first", "second", "word"; n=3}

it did occur to me that splitting a string was possible in lua, eventhough
this is not quite what I wanted to do. The table.concat operation
could also be easily implemented in lua, and using some of the insight
provided by the alternative strrep implementation article on the lua
wiki it should also be reasonably fast. My question should have read more
like "if a join is there, then why isn't a split?".

rgds,

Gunnar