function Util.SubstituteArgs(N,k)N=encodeCommandEscape(N)if type(k)=="\116\097\098\108\101"then for N=1,#k,1 do local z=tostring(N)k[z]=k[N]if k[z]:find("\037\115")then k[z]=string.format("\037\113",k[z])end end end return decodeCommandEscape((N:gsub("\040\036\037\100\043\041\037\098\123\125","\037\049")):gsub("\036\040\037\119\043\041",k))end

function Util.SubstituteArgs(str, replace)
	str = encodeCommandEscape(str)
	-- Convert numerical keys to strings
	if type(replace) == "table" then
		for i = 1, #replace do
			local k = tostring(i)
			replace[k] = replace[i]

			if replace[k]:find("%s") then
				replace[k] = string.format("%q", replace[k])
			end
		end
	end
	return decodeCommandEscape(str:gsub("($%d+)%b{}", "%1"):gsub("$(%w+)", replace))
end
