Module:String2: Difference between revisions

Content deleted Content added
function posnq
retturn nil if either parameter is nil or blank
Line 97:
-- posnq (position, no quotes) returns the numerical start position of the first occurrence
-- of one piece of text ("match") inside another ("str").
-- It returnreturns nil if no match is found, or if either parameter is blank.
-- It takes the text to be searched as the first unnamed parameter, which is trimmed.
-- It takes the text to search for as the second unnamed parameter, which is trimmed and
Line 103:
p.posnq = function(frame)
local str = mw.text.trim(frame.args[1] or "")
--if str == "" then return nil end
local match = mw.text.trim(frame.args[2] or ""):gsub('"', '')
--if str == "" or match == "" then return nil end
-- just take the start position
local pos = str:find(match, 1, true)