Regel 1: Regel 1:
 +
--[[
 +
Method for replacing numerical sequences in string with zero-padded equivalents
 +
]]--
 +
 
local p = {}
 
local p = {}
  
Regel 10: Regel 14:
 
end
 
end
  
 +
--[[
 +
Not currently used
 +
]]--
 
p.padright = function( str, len, char )
 
p.padright = function( str, len, char )
 
if char == nil
 
if char == nil
Regel 22: Regel 29:
 
local str = mw.text.unstrip( frame.args[1] or frame.args.str )
 
local str = mw.text.unstrip( frame.args[1] or frame.args.str )
 
local padlength = mw.text.unstrip( frame.args[2] or frame.args.padlength )
 
local padlength = mw.text.unstrip( frame.args[2] or frame.args.padlength )
--local regpattern = "\%d+"
 
--local matches = string.match( str, regpattern )
 
 
 
local res = string.gsub(  
 
local res = string.gsub(  
 
str,  
 
str,  
Regel 30: Regel 34:
 
function(d) return p.padright( d, 5, '0' ) end
 
function(d) return p.padright( d, 5, '0' ) end
 
)
 
)
 
--
 
 
return res
 
return res
 
end
 
end
  
 
return p
 
return p

Versie van 10 aug 2023 12:18

Module:Pad numbers

Summary
Pad numbers in string. The numbers are 10000 and 53430



--[[
Method for replacing numerical sequences in string with zero-padded equivalents
]]--

local p = {}

p.padleft = function( str, len, char )
	if char == nil
		then char = '0'
		end
	char = '0'
	res = string.rep( char, len - #str ) .. str
	return res
end

--[[
Not currently used
]]--
p.padright = function( str, len, char )
	if char == nil
		then char = '0'
		end
	char = '0'
	res = str .. string.rep( char, len - #str )
	return res
end

function p.main( frame )
	local str = mw.text.unstrip( frame.args[1] or frame.args.str )
	local padlength = mw.text.unstrip( frame.args[2] or frame.args.padlength )
	local res = string.gsub( 
		str, 
		"(%d+)", 
		function(d) return p.padright( d, 5, '0' ) end
	)
	return res
end

return p