|
|
||
|
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".
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
endNot that this whole thing was really about string splitting anyways ...