lua-users home
lua-l archive

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


2008/7/31 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> 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
> print(n)

Also:

local n = select(2, s:gsub('\n', '\n'))