More actions
m both 2 previous edit tests removed |
m remove_var test |
||
Line 1: | Line 1: | ||
local p = {}; | local p = {}; | ||
-- "Default %hero_name% Build" --> "Default Build", or "Default Build" with -1 or +1 for spaces | |||
function p.remove_var(input, spaces) | |||
-- spaces = | |||
-- -1: also remove prefixed character | |||
-- 0 or nil: no character | |||
-- 1: postfixed character | |||
-- Remove text between % and % including the % | |||
local result = input:gsub("%%.-%%", "") | |||
-- If spaces == -1, remove the character before the removed section | |||
if spaces ~= nil and spaces == -1 then | |||
result = result:gsub("%s+%s*", "", 1) -- Removes the preceding space or character | |||
-- If spaces == 1, remove the character after the removed section | |||
elseif spaces ~= nil and spaces == 1 then | |||
result = result:gsub("%s+", "", 1) -- Removes the postfixed space | |||
end | |||
-- Trim any extra whitespace | |||
result = result:gsub("^%s*(.-)%s*$", "%1") | |||
return result | |||
end | |||
--round_to_significant_figures(12345.6789, 3) -- Output: 12300 | --round_to_significant_figures(12345.6789, 3) -- Output: 12300 |