lua-users home
lua-l archive

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

On 3 January 2011 02:05, Steve Litt <> wrote:
> Kein-Hong Man, you were right. For some reason I figured if the pattern was in
> variable then it didn't have to be escaped, but of course this is wrong. So I
> added and used a function called string2pattern, as shown below:
> =======================================
> function string2pattern(str)
>        return string.gsub(str, "%%", "%%%%")
> end
> *********************************
> Obviously for a more robust program I'd need string2pattern() to escape more
> characters than just the percent sign, but for the purposes of UMENU what I've
> done should be enough.
> I might tighten it up a little bit so as not to disturb single percent signs.
> Thanks
> SteveT

You'll want to change \0 to %z, otherwise I can't think of any other
problems off the top of my head....