使用Lua 5.1和gsub函数如何实现区分大小写/不区分大小写和边界模式匹配选项来计算子字符串?
CountSubString = function(s,CtrlID) --< s = string to count
local t = Scintilla.GetText(CtrlID)
if FindReplace.FindCase == 0 then --< no case
if FindReplace.FindWhole == 0 then --< no whole word
local _,count = string.gsub(t,s," ")
return "Found "..count .." occourances of "..s
else --< whole word
local _,count = string.gsub(t,s," ")
return "Found "..count .." occourances of "..s
end
else --< case
if FindReplace.FindWhole == 0 then --< no whole word
local _,count = string.gsub(t,s," ")
return "Found "..count .." occourances of "..s
else --< whole word
local _,count = string.gsub(t,s," ")
return "Found "..count .." occourances of "..s
end
end
end;
我有一个较旧的帖子here有前沿模式,但它也有案例/非案例。