Module:String: Difference between revisions
From HorizonXI Wiki
m (return) |
(join: non-empty arguments only) |
||
| Line 10: | Line 10: | ||
join | join | ||
Using the first argument as a separator, join the remaining arguments together. | Using the first argument as a separator, join the remaining non-empty arguments | ||
together. | |||
Example: | Example: | ||
{{#invoke:String|join|,|apples|bananas|cherries}} | {{#invoke:String|join|,|apples|bananas|cherries}} | ||
| Line 16: | Line 17: | ||
function str.join(frame) | function str.join(frame) | ||
local separator = frame.args[1] | |||
local parts = {} | |||
for k, v in ipairs(frame.args) do | |||
if k > 1 and v ~= '' then | |||
table.insert(parts, v) | |||
end | |||
end | |||
return table.concat(parts, separator) | |||
end | end | ||
return str | return str | ||
Revision as of 08:04, 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 non-empty 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 and v ~= '' then
table.insert(parts, v)
end
end
return table.concat(parts, separator)
end
return str
