[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: split() function
- From: Petite Abeille <petite.abeille@...>
- Date: Mon, 21 Feb 2011 22:08:11 +0100
On Feb 21, 2011, at 9:11 PM, Javier Guerra Giraldez wrote:
> specifically:
>
> http://lua-users.org/wiki/SplitJoin
An oldie, but a goodie, Rici Lake's split:
function string:split(pat)
local st, g = 1, self:gmatch("()("..pat..")")
local function getter(self, segs, seps, sep, cap1, ...)
st = sep and seps + #sep
return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
end
local function splitter(self)
if st then return getter(self, st, g()) end
end
return splitter, self
end
http://lua-users.org/lists/lua-l/2006-12/msg00414.html