lua-users home
lua-l archive

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


Thankyou :) I like the brackets, that's a neat answer and the one I'll use. The function is ok too, though I'd only do that if I wanted further modification, probably.
That said, isn't it strange that there should be special requests for a minimum default? In most things in life we might only want extra information if we ask for it, and Lua, by doing the reverse of this, seems to risk losing the easy and clarity it is so good at.


Rici Lake <lua@ricilake.net> wrote:
(29/08/2004 20:18)


>
>
>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