Re: split method?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: split method?
- From: Etan Reisner <deryni@...>
- Date: 2011年6月29日 13:26:05 -0400
On Wed, Jun 29, 2011 at 11:42:20AM +0200, Valerio Schiavoni wrote:
<snip>
> function split(s, sep)
> local res = {}
> sep = sep or ' '
> for v in s:gmatch('[^' .. sep .. ']+') do
> res[#res + 1] = v
> end
> return res
> end
I've always been partial to http://lua-users.org/lists/lua-l/2011-02/msg01148.html
And a table collecting wrapper around it when necessary:
function split(str, pat)
local t = {}
for seg in ricisplit(str, pat) do
t[#t] = seg
end
return t
end
-Etan