Module:StringLength: Difference between revisions

From Guild of Archivists
No edit summary
 
m (1 revision imported)
 

Latest revision as of 07:26, 30 October 2015

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

-- This is an experiment in writing a Lua module/template
-- It's supposed to measure the length of a string to see that it works correctly with non-ASCII characters

local p = {}

require "mw.ustring"

function p.length(frame)
    result = "The length of ''" .. frame.args.text .. "'' is '''" .. mw.ustring.len( frame.args.text ) .. "'''<br />" ..
        "The byte length of ''" .. frame.args.text .. "'' is '''" .. string.len( frame.args.text ) .. "'''<br />" ..
        "The first 8 letters of ''" .. frame.args.text .. "'' are _'''" .. mw.ustring.sub( frame.args.text, 1, 8 ) .. "'''_<br />" ..
        "The first 8 bytes of ''" .. frame.args.text .. "'' are _'''" .. string.sub( frame.args.text, 1, 8 ) .. "'''_"
    return result
end
 
return p