Difference between revisions of "Module:String"

From FIThydrowiki
Jump to navigation Jump to search
what>IAlex
(fix)
what>IAlex
m (adding "sub" method)
Line 5: Line 5:
 
     return string.len( arg1 )
 
     return string.len( arg1 )
 
end     
 
end     
 +
 +
function p.sub( frame )
 +
    local arg1 = frame.args[1]
 +
    local arg2 = tonumber( frame.args[2] )
 +
    local arg3 = tonumber( frame.args[3] )
 +
    if arg2 and arg3 then
 +
        return string.sub( arg1, arg2, arg3 )
 +
    else
 +
        return ""
 +
    end
 +
end 
  
 
return p
 
return p

Revision as of 11:12, 22 August 2012

local p = {}

function p.length( frame )

   local arg1 = frame.args[1]
   return string.len( arg1 )

end

function p.sub( frame )

   local arg1 = frame.args[1]
   local arg2 = tonumber( frame.args[2] )
   local arg3 = tonumber( frame.args[3] )
   if arg2 and arg3 then
       return string.sub( arg1, arg2, arg3 )
   else
       return ""
   end

end

return p