Module:String: Difference between revisions

92 bytes removed ,  11 years ago
Create module
m (fix)
m>Anomie
(Create module)
Line 1: Line 1:
local p = {}
local str = {}


function p.length( frame )
function str:len( frame )
     local arg1 = frame.args[1]
     return mw.ustring.len( frame.args[1] )
    return string.len( arg1 )
end
end  


function p.sub( frame )
function str:sub( frame )
     local arg1 = frame.args[1]
     return mw.ustring.sub( frame.args[1], tonumber( frame.args[2] ), tonumber( frame.args[3] ) )
    local arg2 = tonumber( frame.args[2] )
end
    local arg3 = tonumber( frame.args[3] )
    if arg2 and arg3 then
        local first = arg2 + 1
        local last  = arg2 + arg3
        return string.sub( arg1, first, last )
    else
        return ""
    end
end


return p
function str:match( frame )
    return mw.ustring.match( frame.args[1], frame.args[2], tonumber( frame.args[3] ) )
end
 
return str
Anonymous user