模块:Quote:修订间差异
来自星露谷物语扩展百科
更多操作
文本切割 |
无编辑摘要 |
||
| 第7行: | 第7行: | ||
-- 计算中文冒号的数量 | -- 计算中文冒号的数量 | ||
local colonCount = 0 | local colonCount = 0 | ||
for _ in | for _ in mw.ustring.gmatch(text, ":") do | ||
colonCount = colonCount + 1 | colonCount = colonCount + 1 | ||
end | end | ||
| 第17行: | 第17行: | ||
-- 找到冒号的位置 | -- 找到冒号的位置 | ||
local colonPos = | local colonPos = mw.ustring.find(text, ":") | ||
-- 检查冒号前面是否有中文逗号或中文句号 | -- 检查冒号前面是否有中文逗号或中文句号 | ||
local beforeColon = | local beforeColon = mw.ustring.sub(text, 1, colonPos - 1) | ||
if | if mw.ustring.find(beforeColon, "[,。]") then | ||
return "" | return "" | ||
end | end | ||
-- 分割文本 | -- 分割文本 | ||
local afterColon = | local afterColon = mw.ustring.sub(text, colonPos + 1) | ||
-- 返回结果 | -- 返回结果 | ||
2025年7月10日 (四) 12:41的版本
local p = {}
-- 检查文本中是否有且仅有一个中文冒号":",且冒号前面没有出现过中文逗号和中文句号
function p.split(frame)
local text = frame.args[1] or ""
-- 计算中文冒号的数量
local colonCount = 0
for _ in mw.ustring.gmatch(text, ":") do
colonCount = colonCount + 1
end
-- 如果不是只有一个冒号,返回空
if colonCount ~= 1 then
return ""
end
-- 找到冒号的位置
local colonPos = mw.ustring.find(text, ":")
-- 检查冒号前面是否有中文逗号或中文句号
local beforeColon = mw.ustring.sub(text, 1, colonPos - 1)
if mw.ustring.find(beforeColon, "[,。]") then
return ""
end
-- 分割文本
local afterColon = mw.ustring.sub(text, colonPos + 1)
-- 返回结果
if frame.args.part == "before" then
return beforeColon
elseif frame.args.part == "after" then
return afterColon
else
-- 默认返回两部分,用 frame.args.separator 分隔(默认为制表符)
local separator = frame.args.separator or "\t"
return beforeColon .. separator .. afterColon
end
end
return p