[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: gsub problem?
- From: Manfred Lotz <manfred.lotz@...>
- Date: Sat, 5 Nov 2005 22:53:40 +0100
On Sat, 05 Nov 2005 19:47:48 -0300
Romulo Bahiense <romulo@icontroller.com.br> wrote:
> > What do I do wrong?
>
> Probably the error is because string.gsub, when called with it's
> third argument as an string, use that as a replacement string.
>
> From the manual:
>
> "string.gsub (s, pat, repl [, n])
>
> (...)
>
....
Yep, I found it in the reference in the meantime.
>
> So, you need to escape those magic characters ('%'):
>
>
> function log(date,msg)
> pat = "%date %str"
> ostr = string.gsub(pat,"%%date",date)
> ostr = string.gsub(ostr,"%%str",(string.gsub(msg, '%%', '%%%%')))
> print(ostr)
> end
>
> log(os.date(),"strange string %4 is this")
>
>
Thanks a lot. That answers my second question from my last post
perfectly.
--
Manfred