Jump to content

Module:StringReplace

From Simple English Wikipedia, the free encyclopedia
Revision as of 13:16, 24 February 2013 by Inkbug (talk | changes) (fix)

Usage

{{#invoke:StringReplace|function_name}}



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