lua-users home
lua-l archive

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


2015-08-20 15:57 GMT-03:00 Soni L. <fakedme@gmail.com>:


On 20/08/15 03:54 PM, Fidelis Assis wrote:
Can also be used for expansion of positional notation

s = '1010'
print((string.gsub(s, "()(.)", function (p, d) return ' + ' .. d .. '*2^' .. #s-p end))

+ 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0

and base conversion.

-- Fidelis

Not the same as using it in the replacement string.

You can do that without the function, just ugly.

print ((string.gsub(s, "()(.)", ' + %2*2^(' .. #s ..'-%1)')))
 
-- Fidelis