Module:String: Difference between revisions
m (adding "sub" method) |
m (make sub match current behaviour of {{str sub}}) |
||
Line 11: | Line 11: | ||
local arg3 = tonumber( frame.args[3] ) | local arg3 = tonumber( frame.args[3] ) | ||
if arg2 and arg3 then | if arg2 and arg3 then | ||
return string.sub( arg1, | local first = arg2 + 1 | ||
local last = first + arg3 | |||
return string.sub( arg1, first, last ) | |||
else | else | ||
return "" | return "" |
Revision as of 11:16, 22 August 2012
Documentation for this module may be created at Module:String/doc
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 local first = arg2 + 1 local last = first + arg3 return string.sub( arg1, first, last ) else return "" end end return p