模块:Utils/String:修订间差异

来自「荏苒之境」
无编辑摘要
无编辑摘要
标签已被回退
第11行: 第11行:
end
end
local t = {}
local t = {}
for str in string.gmatch(str, "([^"..sep.."]+)") do
for str in string.gmatch(str, "([^"..sep.."].)") do
table.insert(t, str)
table.insert(t, str)
end
end

2025年8月11日 (一) 23:18的版本

此模块的文档可以在模块:Utils/String/doc创建

local utils = {}

utils.trim = function(str)
	local res = string.gsub(str, "^%s*(.-)%s*$", "%1")
	return res
end

utils.split = function(str, sep)
	if sep == nil then
		sep = "%s"
	end
	local t = {}
	for str in string.gmatch(str, "([^"..sep.."].)") do
		table.insert(t, str)
	end
	return t
end

utils.unword = function(str)
	local t = {}
	for str in string.gmatch(str, "([^%s]+)") do
		table.insert(t, str)
	end
	return t
end

utils.match_xml_noattr = function(str, tag)
	local res = string.match(str, "<"..tag..">(.-)</"..tag..">")
	return res
end

return utils