1 Oct 2001 16:15
Re: LTN9: Creating Strings Piece by Piece
Luiz Henrique de Figueiredo <lhf <at> tecgraf.puc-rio.br>
2001-10-01 14:15:29 GMT
2001-10-01 14:15:29 GMT
>Any thoughts on making a function that's the opposite as well? Something
>that would take a string and a seperator and return a table whose elements
>contained the original string split apart based on the separator. Or can
>this be done with gsub without creating a bunch of temp strings? I'm not
How about this?
function split(s,t)
local a={}
gsub(s,"(.-)"..t,function (x) tinsert(%a,x) end)
end
(This assumes that the separator t occurs at the end of the string s too.)
gsub only creates the the strings for the captures and the string that is
returned (in this cases, the returned string is ignored).
--lhf
RSS Feed