Toggle menu
505
2.3K
828
21.8K
Deadlock Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Utilities: Difference between revisions

From Deadlock Wiki
Sur (talk | contribs)
m both 2 previous edit tests removed
Sur (talk | contribs)
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