lua-users home
lua-l archive

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



On 29-Aug-04, at 2:12 PM, The Doctor wrote:

Hello, a question about string.gsub and returned values..

If I do:

io.write(string.gsub("Concatenation, Catharsis, Popocatapetl\n","cat","dog"))

I get the count appened to the output, whereas to get the string only, I'd have to do this:

local X=string.gsub("Concatenation, Catharsis, Popocatapetl\n","cat","dog")
io.write(X)

Try this: io.write((string.gsub("Concatenation, Catharsis, Popocatapetl\n", "cat", "dog")))

The extra parenthesis around a function call changes it from multi-return to single-return.

If you don't want to put up with the () stuff in your code, try this:

function string.mygsub(str, pat, repl) return (string.gsub(str, pat, repl)) end

or variations on the theme