[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: help with splitting strings
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Sun, 21 Oct 2007 22:26:14 -0600
Depending on what you're doing, it might be better to use an iterator
with a generic for loop. The function you posted creates a table which
usually isn't desirable if the table is short lived.
If this would be useful:
for str in split(somestring, "pattern") do ... end
Then you might want to use this:
function split(str, delim)
local oldf = 0;
return function()
local start;
if oldf == -1 then return nil end;
oldf, start = str:find(delim, oldf + 1) or -1, oldf;
return str:sub(start + 1, oldf);
end
end;
HTH,
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant