Re: LTN9: Creating Strings Piece by Piece
[Date Prev][
Date Next][Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: LTN9: Creating Strings Piece by Piece
 
- From: Luiz Henrique de Figueiredo <lhf@...>
 
- Date: Mon, 1 Oct 2001 11:15:29 -0300 (EST)
 
>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