1

Using Lua 5.1 and the gsub function how do I implement case sensitive/case insensitive and the frontier pattern matching option to count substrings?

 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;

I've got an older post here with the frontier pattern but it's having it case/non case also.

Community
  • 1
  • 1
Col_Blimp
  • 779
  • 2
  • 8
  • 26

0 Answers0