[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A citation on Lua
- From: "Leo Razoumov" <slonik.az@...>
- Date: Mon, 18 Dec 2006 14:31:39 -0500
On 12/18/06, dcharno <dcharno@comcast.net> wrote:
> I think for him lack of 'split' counts as a design flaw?
Couldn't he just use gmatch ...
function strsplit(s, delim)
return string.gmatch(s, string.format("[^s]+", delim))
end
I would presume you really meant something like this
function strsplit(s, delim)
local t= {}
for x in string.gmatch(s, string.format("[^%s]+", delim)) do
t[#t+1]= x
end
return t
end
In any case it is NOT equivalent to a split operation (Ruby, Pearl)
that splits on a matching pattern. To see the difference, choose a
delimiter to be a string of several characters like delim="SEP". The
strsplit() implementation above will skip all occurrences of letters
S,E,P anywhere in the string which is very different from splitting on
a single string "SEP".
It would be great if someone on this list could show a short and
convenient idiom for "split" operation on strings.
--Leo--