result = mw.ustring.gsub(source_str, "["..chars.."]", '')
return result;
end
--[[
Split
This function Splits a string based on a pattern, returns nth substring based on count.
Usage:
{{#invoke:StringFunc|split|source_string|pattern|count|plain}}
Parameters:
source: The string to return a subset of
pattern: The pattern or string to split on
count: The nth substring based on the pattern to return
plain: A flag indicating if the pattern should be understood as plain text, defaults to true.
]]
function p.split( frame )
local new_args = p._getParameters( frame.args, {'source', 'pattern', 'count', 'plain'})
local source_str = new_args['source'] or '';
local pattern = new_args['pattern'] or '';
if source_str == '' or pattern == '' then
return source_str;
end
local l_plain = p._getBoolean( new_args['plain'] or true );
local split = mw.text.split(source_str, pattern, l_plain)
return split[tonumber(new_args['count'] or 1)]
end
|