Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Matroc/Str swap
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function p.swapreplace(frame) local a_string = frame.args[1] or "" if a_string == nil or a_string == "" then error("Missing string on which to perform swap!") end local noofargs = 0 for i = 1, 10, 1 do if frame.args[i] ~= nil then noofargs = i end -- END if end -- END for if noofargs ~= 4 then error("Incorrect number of arguments: " .. noofargs .. " Required = 4!") end -- END if local nooftimes = tonumber(frame.args[4]) if nooftimes == nil then nooftimes = 1 elseif nooftimes == "" then nooftimes = 1 elseif nooftimes <= 0 then nooftimes = 1 end local swap = frame.args[2] or "" if swap == nil then swap = "" end if swap == "" then error("Missing String to Swap!") end local swapwith = frame.args[3] or "" if swapwith == nil then swapwith = "" end if swapwith == "" then error("Missing String to Swap with!") end a_string = (a_string:gsub(swap,"@2@2" .. swap .. "@2@2", nooftimes)) a_string = (a_string:gsub(swapwith,"@3@3" .. swapwith .. "@3@3", nooftimes)) a_string = (a_string:gsub("@3@3" .. swapwith .. "@3@3", swap, nooftimes)) a_string = (a_string:gsub("@2@2" .. swap .. "@2@2", swapwith, nooftimes)) return a_string end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Matroc/Str swap/doc
(
edit
)