[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: new string functions (was Re: Standard Libraries....)
- From: David Manura <dm.lua@...>
- Date: Mon, 18 Jan 2010 21:23:38 -0500
On Mon, Jan 18, 2010 at 12:41 AM, Vaughan McAlley wrote:
> Could string.split() be like string.gmatch(), but just return what
> isn’t matched (ie what lies between the matches)?
That's a good insight: They are in some ways complements of each
other, especially if you implement string.split to return an iterator
as well, as does Rici's implementation [1].
Note that
for w in (","):gmatch(",") do print("[" .. w .. "]") end --> [,]
for w in ("a"):gmatch("") do print("[" .. w .. "]") end --> [] []
provides a further justification imposing this behavior [2]
for w in (","):split(",") do print("[" .. w .. "]") end --> [] []
for w in ("a"):split("") do print("[" .. w .. "]") end --> [] [a]
[] (not [a])
[1] http://lua-users.org/lists/lua-l/2006-12/msg00414.html
[2] http://lua-users.org/lists/lua-l/2009-12/msg00952.html