Module:Text count
From EverybodyWiki Bios & Wiki
| This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Usage
Counts the number of times an pattern appears in the arguments that get passed on to this module.
{{#invoke:Text count|main}}
local z = {}
function z.main(frame)
local config = frame.args
local errors = {}
if not config.text then
table.insert(errors, "no text argument. Please provide the text that you wish to count strings in.")
end
if not config.pattern then
table.insert(errors, "no pattern argument. Please provide the string you wish to search for.")
end
if table.maxn(errors) == 0 then
local temp, count = mw.ustring.gsub(config.text, config.pattern, "%0")
return count
else
return table.concat(errors, " ")
end
end
return z
