Anonymous user
Module:String2: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
retturn nil if either parameter is nil or blank
(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
-- 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('"', '')
-- just take the start position
local pos = str:find(match, 1, true)
|