Re: A citation on Lua
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: A citation on Lua
- From: dcharno <dcharno@...>
- Date: 2006年12月19日 10:00:49 -0500
Leo Razoumov wrote:
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".
You're right. I rarely split on anything other than commas or
semicolons. Here is a version that seems to handle the perl examples I
could find and was a little shorter than other samples I saw:
function strsplit(s, delim)
local t = {}
local pat = "(.-)" .. delim .. "(.+)"
local c1, c2
repeat
c1, c2 = string.match(s, pat)
t[#t+1] = c1 or s
s = c2
until c1 == nil
return t
end
Not that this whole thing was really about string splitting anyways ...