lua-users home
lua-l archive

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


> >How about the following:
> >
> >-- strip leading and trailing white space from a line
> >function strip(l)
> >     return gsub(l, "%s*(.*)%s*", "%1", 1)
> >end
>
> Actually, this wouldn't work. The trailing spaces are captured. Try:
>
>       return gsub(l, "%s*(.-)%s*$", "%1", 1)

Oops...

> >-- remove a prefix p from s
> >-- return the beheaded s and the removed prefix
> >function behead(s, p)
> >     local s2, z
> >
> >     z, z, p, s2 = strfind(s, p .. ")(.*)")
>
> There's an open-parenthesis missing:
>
>      z, z, p, s2 = strfind(s, "(".. p .. ")(.*)")

Oops again...

I should've put a "not actually run" warning on those...

-- 
http://sc3d.org/rrt/
"Reality is what refuses to disappear when you stop believing in it" -
Philip K. Dick