Module:String2: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(sync from sandbox - handling UTF-8 in ucfirst) |
(implement findlast) |
||
Line 68: | Line 68: | ||
end |
end |
||
return table.concat(words, " ") |
return table.concat(words, " ") |
||
end |
|||
-- findlast finds the last item in a list |
|||
-- the first unnamed parameter is the list |
|||
-- the second, optional unnamed parameter is the list separator (default = comma space) |
|||
-- returns the whole list if separator not found |
|||
p.findlast = function(frame) |
|||
local s = mw.text.trim( frame.args[1] or "" ) |
|||
local sep = mw.text.trim( frame.args[2] or ", " ) |
|||
pattern = ".*" .. sep .."(.*)" |
|||
a, b, last = s:find(pattern) |
|||
if a then |
|||
return last |
|||
else |
|||
return s |
|||
end |
|||
end |
end |
||