"ഘടകം:String" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

Content deleted Content added
(ചെ.) en:Module:String എന്നതിൽ നിന്ന് ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു
(ചെ.) ഒരു ഫങ്ക്ഷൻ ചേർത്തു
വരി 576:
end
return boolean_value
end
--[[
Split (Added for the functionality equal to that in Catalan wiki
 
This function Splits a string based on a separator, returns nth substring based on count.
 
Usage:
{{#invoke:StringFunc|split|source_string|separator|count}}
 
Parameters:
source: The string to return a subset of
separator: The string to split on
count: The nth substring based on the separator to return
]]
function p.split( frame )
local new_args = _getParameters( frame.args, {'source', 'separator', 'count'} )
local source_str = new_args['source'] or ''
local separator = new_args['separator'] or ''
local separator_len = mw.ustring.len(separator)
if source_str == '' or separator == '' then
return source_str;
end
local ret_count = tonumber( new_args['count'] ) or 1
if ret_count < 1 then
return ""
end
local start = 1
local iter = mw.ustring.find(source_str, separator, start, true)
if iter == nil then
if ret_count == 1 then
return source_str
else
return ""
end
else
iter = iter - 1
end
if ret_count == 1 then
return mw.ustring.sub( source_str, start, iter)
end
for i=2, ret_count do
start = iter+separator_len + 1
iter = mw.ustring.find(source_str, separator, start, true)
if iter == nil then
if ret_count == i then
return mw.ustring.sub(source_str, start, mw.ustring.len(source_str))
else
return ""
end
else
iter = iter - 1
end
end
return mw.ustring.sub( source_str,start,iter)
end
 
"https://ml.wikipedia.org/wiki/ഘടകം:String" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്