模块:StringTPC
外观
此模块的文档可以在模块:StringTPC/doc创建
local p = {}
function p (frame)
local A = frame.args[1]
local B = frame.args[2]
local count = 0
local pos = 1
-- 使用 string.find 循环查找
while pos <= #A do
local start_pos, end_pos = string.find(A, B, pos, true) -- true 表示纯文本匹配
if start_pos then
count = count + 1
pos = end_pos + 1 -- 移动到匹配结束后的位置(不重叠)
else
break
end
end
return count
end
return count