[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: sscanf like in Lua
- From: Wesley Smith <wesley.hoke@...>
- Date: Mon, 23 Aug 2010 22:07:49 +0200
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)