Module:StringHelper
Jump to navigation
Jump to search
local p = {}
-- copy mw.ustring methods for k, v in pairs( mw.ustring ) do p[k] = v end
-- true if string 's' starts with string 'prefix' function p.startswith( s, prefix )
return p.sub( s, 1, p.len( prefix ) ) == prefix
end
-- true if string 's' ends with string 'suffix' function p.endswith( s, suffix )
return suffix == or p.sub( s, 0 - p.len( suffix ) ) == suffix
end
-- strip characters 'chars' from beginning and end of string 's' function p.strip( s, chars )
s = p.gsub( s, '^[' .. chars .. ']*', ) s = p.gsub( s, '[' .. chars .. ']*$', ) return s
end
-- line iterator function p.lines( s )
return p.gmatch( s, "[^\r\n]+" )
end
return p