[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to count the number of lines in a string?
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Thu, 31 Jul 2008 06:36:34 -0600
On Thu, Jul 31, 2008 at 5:47 AM, Jerome Vuarand
> 2008/7/31 Luiz Henrique de Figueiredo <firstname.lastname@example.org>:
>>> what is the most efficient way of counting the number of lines?
>> Try this one:
>> local n=0
>> for i in s:gmatch("\n") do n=n+1 end
> local n = select(2, s:gsub('\n', '\n'))
You can make it so just an empty string is pushed if there is at least
local n = select(2, s:gsub("[^\n]*\n[^\n]*", ""))
I haven't benchmarked it though.
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."