Jump to content

Module:StringReplace

From Simple English Wikipedia, the free encyclopedia
Revision as of 13:15, 24 February 2013 by Inkbug (talk | changes) (Created page with 'local p = {} function escapePattern(text) return string.gsub(text, "[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1") end function p.replace_all(frame) local str = fram...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 str:gsub(str, escapePattern(strToFind), escapePattern(strToreplaceWith))
end
return p