lua-users home
lua-l archive

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


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