Difference between revisions of "Module:String"

From WPRDC Wiki
Jump to navigation Jump to search
>IAlex
m (fix)
>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

Revision as of 03:20, 19 February 2013

Documentation for this module may be created at Module:String/doc

local str = {}

function str:len( frame )
    return mw.ustring.len( frame.args[1] )
end

function str:sub( frame )
    return mw.ustring.sub( frame.args[1], tonumber( frame.args[2] ), tonumber( frame.args[3] ) )
end

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

return str