Module:String: Difference between revisions

From HorizonXI Wiki
(module for general string functions (starting with "join"))
 
m (return)
Line 27: Line 27:
return table.concat(parts, separator)
return table.concat(parts, separator)
end
end
return str

Revision as of 08:01, 1 September 2025

Documentation for this module may be created at Module:String/doc

--[[

A module for general string functions.

]]

local str = {}

--[[
join

Using the first argument as a separator, join the remaining arguments together.
Example:
{{#invoke:String|join|,|apples|bananas|cherries}}
]]

function str.join(frame)
	local separator = frame.args[1]
	local parts = {}

	for k, v in ipairs(frame.args) do
		if k > 1 then
			table.insert(parts, v)
		end
	end

	return table.concat(parts, separator)
end

return str