lua-users home
lua-l archive

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


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