lua-users home
lua-l archive

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



On Sun, Jan 25, 2009 at 8:41 PM, Sam Roberts <vieuxtech@gmail.com> wrote:
On Sat, Jan 24, 2009 at 4:56 PM, Vaughan McAlley <ockegheim@gmail.com> wrote:
> OK, so to fix this problem I need to tell it exactly how many results
> I want. My function:
>
> function f(s)
>    if string.byte(s) == 42 then
>        -- do stuff if and only if s starts with "*"
>    end
> end

Or

if string.find(s, "^*") then
 -- do stuff
end

Or

if s:find("^*") then
 -- do stuff
end

Sam

If you're just testing a single character at the start, comparing to string.sub(s,1,1) - or s:sub(1,1) - seems like a more obvious route to take.

-Duncan