Module:Cmap: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
(Created page with "local p = {} --p stands for package function p.cmap(frame) return frame.args[1] end")
 
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 2: Line 2:


function p.cmap(frame)
function p.cmap(frame)
return frame.args[1]
if frame.args[1] and frame.args[2] and frame.args[3] then
smaller, _ = mw.ustring.gsub(frame.args[1], frame.args[2], frame.args[3])
return smaller
end
return ''
end
end
return p

Latest revision as of 19:08, 6 January 2024

Returns arg1 with all instances of arg2 replaced with arg3.

Example[edit | hide]

{{#invoke:cmap|cmap|needle in haystack|needle|hay}}
hay in haystack

local p = {} --p stands for package

function p.cmap(frame)
	if frame.args[1] and frame.args[2] and frame.args[3] then
		smaller, _ = mw.ustring.gsub(frame.args[1], frame.args[2], frame.args[3])
		return smaller
	end
	return ''
end

return p