[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: sscanf like in Lua
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 23 Aug 2010 17:55:28 -0300
> On Mon, Aug 23, 2010 at 9:58 PM, Ted Unangst <ted.unangst@gmail.com> wrote:
> > On Mon, Aug 23, 2010 at 3:47 PM, Jose Marin <jose_marin2@yahoo.com.br> wrote:
> >> Hi,
> >>
> >> What's the most efficient equivalent in Lua of
> >>
> >> sscanf(str, " val %d | %d", &v1, &v2);
> >
> > v1, v2 = str:match("val (%d+) | (%d+)")
> >
> don't forget that %d takes an int:
>
> v1, v2 = str:match("val (%d+) | (%d+)")
> v1, v2 = tonumber(v1), tonumber(v2)
and that blanks in scanf consume spans of white spaces.
-- Roberto