Jump to content

Module:StringReplace

From Simple English Wikipedia, the free encyclopedia
Revision as of 13:35, 24 February 2013 by Inkbug (talk | changes) (should work now)

Usage

{{#invoke:StringReplace|function_name}}



local p = {}
function p.escape_pattern(text)
    local r = string.gsub(text, "[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1")
    return r
end
function p.replace_all(frame)
    local str = frame.args[1]
    local strToFind = frame.args[2]
    local strToreplaceWith = frame.args[3]
    local r = string.gsub(str, p.escape_pattern(strToFind), p.escape_pattern(strToreplaceWith))
    return r
end
return p