[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: GSUB count problem
- From: Shmuel Zeigerman <shmuz@...>
- Date: Wed, 17 Sep 2008 23:51:17 +0300
Shmuel Zeigerman wrote:
Try this:
_, count = bytes:gsub("\208\169\175", "")
or this:
_, count = bytes:gsub(string.char(0xD3,0xA9,0xAF), "")
These methods are not safe, as the characters can have special meaning
in the pattern, e.g. "+", "[", etc.
Here's a function that is hopefully safe (not tested):
function count(subj, ...)
local cnt, start = 0, 1
local patt = string.char(...)
while true do
local s, e = subj:find(patt, start, true)
if not s then break end
cnt, start = cnt+1, e+1
end
return cnt
end
usage example:
local cnt = count(subj, 0xD3, 0xA9, 0xAF)
--
Shmuel