<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="vi">
	<id>https://bktt.vn/index.php?action=history&amp;feed=atom&amp;title=M%C3%B4_%C4%91un%3AString2</id>
	<title>Mô đun:String2 - Lịch sử thay đổi</title>
	<link rel="self" type="application/atom+xml" href="https://bktt.vn/index.php?action=history&amp;feed=atom&amp;title=M%C3%B4_%C4%91un%3AString2"/>
	<link rel="alternate" type="text/html" href="https://bktt.vn/index.php?title=M%C3%B4_%C4%91un:String2&amp;action=history"/>
	<updated>2026-04-03T23:35:40Z</updated>
	<subtitle>Lịch sử thay đổi của trang này ở wiki</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://bktt.vn/index.php?title=M%C3%B4_%C4%91un:String2&amp;diff=9559&amp;oldid=prev</id>
		<title>Tttrung: Tạo trang mới với nội dung “local p = {}   p.upper = function(frame) 	local s = mw.text.trim(frame.args[1] or &quot;&quot;) 	return string.upper(s) end  p.lower = function(frame) 	local s = mw…”</title>
		<link rel="alternate" type="text/html" href="https://bktt.vn/index.php?title=M%C3%B4_%C4%91un:String2&amp;diff=9559&amp;oldid=prev"/>
		<updated>2020-12-01T01:46:02Z</updated>

		<summary type="html">&lt;p&gt;Tạo trang mới với nội dung “local p = {}   p.upper = function(frame) 	local s = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;) 	return string.upper(s) end  p.lower = function(frame) 	local s = mw…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Trang mới&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
p.upper = function(frame)&lt;br /&gt;
	local s = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	return string.upper(s)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.lower = function(frame)&lt;br /&gt;
	local s = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	return string.lower(s)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.sentence = function (frame )&lt;br /&gt;
	frame.args[1] = string.lower(frame.args[1])&lt;br /&gt;
	return p.ucfirst(frame)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.ucfirst = function (frame )&lt;br /&gt;
	local s =  mw.text.trim( frame.args[1] or &amp;quot;&amp;quot; )&lt;br /&gt;
	local s1 = &amp;quot;&amp;quot;&lt;br /&gt;
	-- if it's a list chop off and (store as s1) everything up to the first &amp;lt;li&amp;gt;&lt;br /&gt;
	local lipos = mw.ustring.find(s, &amp;quot;&amp;lt;li&amp;gt;&amp;quot; )&lt;br /&gt;
	if lipos then&lt;br /&gt;
		s1 = mw.ustring.sub(s, 1, lipos + 3)&lt;br /&gt;
		s = mw.ustring.sub(s, lipos + 4)&lt;br /&gt;
	end&lt;br /&gt;
	-- s1 is either &amp;quot;&amp;quot; or the first part of the list markup, so we can continue&lt;br /&gt;
	-- and prepend s1 to the returned string&lt;br /&gt;
	local letterpos&lt;br /&gt;
	if mw.ustring.find(s, &amp;quot;^%[%[[^|]+|[^%]]+%]%]&amp;quot;) then&lt;br /&gt;
		-- this is a piped wikilink, so we capitalise the text, not the pipe&lt;br /&gt;
		local _&lt;br /&gt;
		_, letterpos = mw.ustring.find(s, &amp;quot;|%A*%a&amp;quot;) -- find the first letter after the pipe&lt;br /&gt;
	else&lt;br /&gt;
		letterpos = mw.ustring.find(s, '%a')&lt;br /&gt;
	end&lt;br /&gt;
	if letterpos then&lt;br /&gt;
		local first = mw.ustring.sub(s, 1, letterpos - 1)&lt;br /&gt;
		local letter = mw.ustring.sub(s, letterpos, letterpos)&lt;br /&gt;
		local rest = mw.ustring.sub(s, letterpos + 1)&lt;br /&gt;
		return s1 .. first .. mw.ustring.upper(letter) .. rest&lt;br /&gt;
	else&lt;br /&gt;
		return s1 .. s&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.title = function (frame )&lt;br /&gt;
	-- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html&lt;br /&gt;
	-- recommended by The U.S. Government Printing Office Style Manual:&lt;br /&gt;
	-- &amp;quot;Capitalize all words in titles of publications and documents,&lt;br /&gt;
	-- except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.&amp;quot;&lt;br /&gt;
	local alwayslower = {['a'] = 1, ['an'] = 1, ['the'] = 1,&lt;br /&gt;
		['and'] = 1, ['but'] = 1, ['or'] = 1, ['for'] = 1,&lt;br /&gt;
		['nor'] = 1, ['on'] = 1, ['in'] = 1, ['at'] = 1, ['to'] = 1,&lt;br /&gt;
		['from'] = 1, ['by'] = 1, ['of'] = 1, ['up'] = 1 }&lt;br /&gt;
	local res = ''&lt;br /&gt;
	local s =  mw.text.trim( frame.args[1] or &amp;quot;&amp;quot; )&lt;br /&gt;
	local words = mw.text.split( s, &amp;quot; &amp;quot;)&lt;br /&gt;
	for i, s in ipairs(words) do&lt;br /&gt;
		s = string.lower( s )&lt;br /&gt;
		if( i &amp;gt; 1 and alwayslower[s] == 1) then&lt;br /&gt;
			-- leave in lowercase&lt;br /&gt;
		else&lt;br /&gt;
			s = mw.getContentLanguage():ucfirst(s)&lt;br /&gt;
		end&lt;br /&gt;
		words[i] = s&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(words, &amp;quot; &amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- findlast finds the last item in a list&lt;br /&gt;
-- the first unnamed parameter is the list&lt;br /&gt;
-- the second, optional unnamed parameter is the list separator (default = comma space)&lt;br /&gt;
-- returns the whole list if separator not found&lt;br /&gt;
p.findlast = function(frame)&lt;br /&gt;
	local s =  mw.text.trim( frame.args[1] or &amp;quot;&amp;quot; )&lt;br /&gt;
	local sep = frame.args[2] or &amp;quot;&amp;quot;&lt;br /&gt;
	if sep == &amp;quot;&amp;quot; then sep = &amp;quot;, &amp;quot; end&lt;br /&gt;
	local pattern = &amp;quot;.*&amp;quot; .. sep .. &amp;quot;(.*)&amp;quot;&lt;br /&gt;
	a, b, last = s:find(pattern)&lt;br /&gt;
	if a then&lt;br /&gt;
		return last&lt;br /&gt;
	else&lt;br /&gt;
		return s&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- stripZeros finds the first number and strips leading zeros (apart from units)&lt;br /&gt;
-- e.g &amp;quot;0940&amp;quot; -&amp;gt; &amp;quot;940&amp;quot;; &amp;quot;Year: 0023&amp;quot; -&amp;gt; &amp;quot;Year: 23&amp;quot;; &amp;quot;00.12&amp;quot; -&amp;gt; &amp;quot;0.12&amp;quot;&lt;br /&gt;
p.stripZeros = function(frame)&lt;br /&gt;
	local s = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local n = tonumber( string.match( s, &amp;quot;%d+&amp;quot; ) ) or &amp;quot;&amp;quot;&lt;br /&gt;
	s = string.gsub( s, &amp;quot;%d+&amp;quot;, n, 1 )&lt;br /&gt;
	return s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- nowiki ensures that a string of text is treated by the MediaWiki software as just a string&lt;br /&gt;
-- it takes an unnamed parameter and trims whitespace, then removes any wikicode&lt;br /&gt;
p.nowiki = function(frame)&lt;br /&gt;
	local str = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	return mw.text.nowiki(str)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- posnq (position, no quotes) returns the numerical start position of the first occurrence&lt;br /&gt;
-- of one piece of text (&amp;quot;match&amp;quot;) inside another (&amp;quot;str&amp;quot;).&lt;br /&gt;
-- It returns nil if no match is found, or if either parameter is blank.&lt;br /&gt;
-- It takes the text to be searched in as the first unnamed parameter, which is trimmed.&lt;br /&gt;
-- It takes the text to match as the second unnamed parameter, which is trimmed and&lt;br /&gt;
-- any double quotes &amp;quot; are stripped out.&lt;br /&gt;
p.posnq = function(frame)&lt;br /&gt;
	local str = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local match = mw.text.trim(frame.args[2] or &amp;quot;&amp;quot;):gsub('&amp;quot;', '')&lt;br /&gt;
	if  str == &amp;quot;&amp;quot; or match == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	-- just take the start position&lt;br /&gt;
	local pos = str:find(match, 1, true)&lt;br /&gt;
	return pos&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- split splits text at boundaries specified by separator&lt;br /&gt;
-- and returns the chunk for the index idx (starting at 1)&lt;br /&gt;
-- #invoke:String2 |split |text |separator |index |true/false&lt;br /&gt;
-- #invoke:String2 |split |txt=text |sep=separator |idx=index |plain=true/false&lt;br /&gt;
-- if plain is false/no/0 then separator is treated as a Lua pattern - defaults to plain=true&lt;br /&gt;
p.split = function(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not(args[1] or args.txt) then args = frame:getParent().args end&lt;br /&gt;
	local txt = args[1] or args.txt or &amp;quot;&amp;quot;&lt;br /&gt;
	if txt == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	local sep = (args[2] or args.sep or &amp;quot;&amp;quot;):gsub('&amp;quot;', '')&lt;br /&gt;
	local idx = tonumber(args[3] or args.idx) or 1&lt;br /&gt;
	local plain = (args[4] or args.plain or &amp;quot;true&amp;quot;):sub(1,1)&lt;br /&gt;
	plain = (plain ~= &amp;quot;f&amp;quot; and plain ~= &amp;quot;n&amp;quot; and plain ~= &amp;quot;0&amp;quot;)&lt;br /&gt;
	local splittbl = mw.text.split( txt, sep, plain )&lt;br /&gt;
	if idx &amp;lt; 0 then idx = #splittbl + idx + 1 end&lt;br /&gt;
	return splittbl[idx]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- val2percent scans through a string, passed as either the first unnamed parameter or |txt=&lt;br /&gt;
-- it converts each number it finds into a percentage and returns the resultant string.&lt;br /&gt;
p.val2percent = function(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if not(args[1] or args.txt) then args = frame:getParent().args end&lt;br /&gt;
	local txt = mw.text.trim(args[1] or args.txt or &amp;quot;&amp;quot;)&lt;br /&gt;
	if txt == &amp;quot;&amp;quot; then return nil end&lt;br /&gt;
	local function v2p (x)&lt;br /&gt;
		x = (tonumber(x) or 0) * 100&lt;br /&gt;
		if x == math.floor(x) then x = math.floor(x) end&lt;br /&gt;
		return x .. &amp;quot;%&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	txt = txt:gsub(&amp;quot;%d[%d%.]*&amp;quot;, v2p) -- store just the string&lt;br /&gt;
	return txt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Tttrung</name></author>
	</entry>
</feed>