[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The Alphanum Algorithm for Lua
- From: Ico Doornekamp <lua@...>
- Date: Tue, 3 Jun 2008 19:15:18 +0200
* On 2008-06-03 Andrew Wilson <agrwagrw@gmail.com> wrote :
> Lua list:
>
> While trying to do a nice natural sorting style example for Lua based
> on site http://www.davekoelle.com/alphanum.html site, I wasn't verify
> satisfied with my example,
> does anyone have a better method of splitting a string into table of
> strings and numbers, than my chunkString function below. I know I'm
> missing some simple string.gmatch way of doing it. Whole example is
> included...
What about:
function chunkString(str)
local c = {}
for a, b in str:gmatch("(%d*)(%D*)") do
if #a>0 then c[#c+1] = tonumber(a) end
if #b>0 then c[#c+1] = b end
end
return c
end
--
:wq
^X^Cy^K^X^C^C^C^C