lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.