[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Loop through a string "lines" at a time
- From: Ketmar Dark <ketmar@...>
- Date: Tue, 3 Jul 2007 10:20:35 +0300
On Mon, 2 Jul 2007 17:52:52 -0400
"RJP Computing" <rjpcomputing@gmail.com> wrote:
> Is there a way to loop through a string "lines" at a time?
s = "youstring\nline2\nline3";
for l in s:gmatch("[^\n]*") do
print(l.."|");
end;
this will give superfluous empty line after the "line3".
or:
s = <the-same>
for l in string.gmatch(s.."\n", "([^\n]*)\n") do
print(l.."|");
end;
this will not give extra lines, but you need to concat string with
"\n". i personally prefer the 1st snippet (to avoid string
concatenation, just a matter of taste), 'cause i just don't care 'bout
empty lines in the end of the data most of the time.