Module:String2/sandbox: Difference between revisions

Content deleted Content added
function split
allow wrapper for split
Line 111:
-- if plain is false/no/0 then separator is treated as a Lua pattern - defaults to plain=true
p.split = function(frame)
local txtargs = frame.args[1] or frame:getParent().args.txt or ""{}
local txt = args[1] or args.txt or ""
if txt == "" then return nil end
local sep = (frame.args[2] or frame.args.sep or ""):gsub('"', '')
local idx = tonumber(frame.args[3] or frame.args.idx) or 1
local plain = (frame.args[4] or frame.args.plain or "true"):sub(1,1)
plain = (plain ~= "f" and plain ~= "n" and plain ~= "0")
return mw.text.split( txt, sep, plain )[idx]