模块:Utils/String:修订间差异
来自「荏苒之境」
无编辑摘要 |
无编辑摘要 |
||
第4行: | 第4行: | ||
local res = string.gsub(str, "^%s*(.-)%s*$", "%1") | local res = string.gsub(str, "^%s*(.-)%s*$", "%1") | ||
return res | 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 | end | ||
2025年8月11日 (一) 23:03的版本
此模块的文档可以在模块: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