[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: David Manura <dm.lua@...>
- Date: Fri, 1 Aug 2008 00:27:11 +0000 (UTC)
Luiz Henrique de Figueiredo writes:
> > ...
> > local n = select(2, s:gsub("[^\n]*\n[^\n]*", ""))
> Or this:
> local _,n = s:gsub('.-\n', '')
May be less memory efficient but terser:
return # s:gsub("[^\n]", "")
The general form can answer queries such as, "How many characters in a given set
are in a string?"