Difference between revisions of "Module:SandboxUString"
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
function p.showCode(a) | function p.showCode(a) | ||
pageContent = string.byte( | str = "The Quick Brown Fox Jumped over the lazy dog." | ||
pageContent = string.byte(str, 5, 9) | |||
return pageContent | return pageContent | ||
end | end |
Revision as of 15:32, 10 January 2022
Documentation for this module may be created at Module:SandboxUString/doc
local p = {}
function p.countChar(a)
textLength = mw.ustring.len(mw.getCurrentFrame().args[1])
local div = mw.html.create( 'h1' )
div
:wikitext( "The number of characters is:" .. tostring(textLength) )
return a:preprocess(tostring( div ))
end
function p.showCode(a)
str = "The Quick Brown Fox Jumped over the lazy dog."
pageContent = string.byte(str, 5, 9)
return pageContent
end
function p.luaSourceCodeText(a)
pageContent = string.byte(mw.getCurrentFrame().args[1], 0, -1)
local div = mw.html.create( 'syntaxhighlight' )
div
:attr( 'lang', 'lua' )
:wikitext( "-- Content:" .. tostring(string.char(pageContent)) )
return a:preprocess(tostring( div ))
end
function p.byte()
return ';byte\n:mw.ustring.byte(\'\\\') is ' .. mw.ustring.byte("\\") .. '\n'
end
function p.char()
return ';char\n:mw.ustring.char(92) is ' .. mw.ustring.char(92) .. '\n'
end
function p.codepoint()
return ';byte\n:mw.ustring.codepoint(\'张\') is ' .. mw.ustring.codepoint("张") .. '\n'
end
function p.ustringchar()
return ';byte\n:mw.ustring.char(24352) is ' .. mw.ustring.char(24352) .. '\n'
end
function p.length()
return ';byte\n:mw.ustring.len(\'张三\') is ' .. mw.ustring.len("张三") .. '\n'
end
function p.find()
return ';find\n:string.find(\'that\', \'at\') is ' .. string.find('that', 'at') .. '\n'
end
function p.format()
return ';format\n:string.format(\'%.2f\', 0) is ' .. string.format('%.2f', 0) .. '\n'
end
function p.gmatch()
local result = ';gmatch\n:'
for word in string.gmatch('This is a test', '%w+') do
result = result .. word .. '-'
end
return result .. '\n'
end
function p.gsub()
return ';gsub\n:string.gsub(\'This is a test\', \'%s\', \'-\') is ' .. string.gsub('This is a test', '%s', '-') .. '\n'
end
function p.len()
return ';len\n:string.len(\'len\') is ' .. string.len('len') .. '\n'
end
function p.lower()
return ';lower\n:string.lower(\'LOWER\') is ' .. string.lower('LOWER') .. '\n'
end
function p.match()
return ';match\n:string.match(\'This is a test!\', \'.\', -1) is ' .. string.match('This is a test!', '.', -1) .. '\n'
end
function p.rep()
return ';rep\n:string.rep(\'*\', 5) is ' .. string.rep('*', 5) .. '\n'
end
function p.reverse()
return ';reverse\n:string.reverse(\'reverse\') is ' .. string.reverse('reverse') .. '\n'
end
function p.sub()
return ';sub\n:string.sub(\'that\', 2, 3) is ' .. string.sub('that', 2, 3) .. '\n'
end
function p.upper()
return ';upper\n:string.upper(\'upper\') is ' .. string.upper('upper') .. '\n'
end
return p