[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to upgrade string.gsub() from 5.0.2 to 5.1 (beta)
- From: Romulo Bahiense <romulo@...>
- Date: Tue, 20 Dec 2005 13:00:49 -0200
Henderson, Michael D wrote:
Okay, I re-read Roberto Ierusalimschy's original post a couple three
times and added an empty string to my return statement. I am not sure
*why* it works, but it does.
Because of the new behavior of gsub, which now accepts a table (and not
only a string or function).
Say:
local t = {Hello='World', foo='bar'}
1) print(string.gsub('Hello, foo!', '(%w+)', t))
> World, bar
2) print(string.gsub('Mister Anderson, Welcome back', '(%w+)', t))
> Mister Anderson, Welcome back
Note that number 2 didn't had an equivalent key on t, so gsub kept it
(in other words: the old behavior would replace all words from the
source string to "")
--rb