[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to count the number of lines in a string?
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Thu, 31 Jul 2008 07:07:27 -0600
On Thu, Jul 31, 2008 at 7:00 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> You can make it so just an empty string is pushed if there is at least
>> one newline:
>>
>> local n = select(2, s:gsub("[^\n]*\n[^\n]*", ""))
>
> Or this:
> local _,n = s:gsub('.-\n', '')
The only "problem" with that is if there is anything following the
final newline character, it will be returned by gsub.
So perhaps the final best version would be:
local _,n = s:gsub(".-\n[^\n]*", "")
Cheers,
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant