Hello, I am currently creating a function to find the amount of specified characters in a string. This is the current solution that I have.
local str = "jKa1sd1aSDd111sd1"
local function FindCharacters(txt)
local input = txt
local finds = 0
local place = 0
while true do
if finds == 0 then
if input:find('1') then
finds = 1
place = input:find('1') + 1
else
return 0
end
else
if input:find('1', place) then
finds += 1
place = input:find('1', place) + 1
else
return finds
end
end
end
end
print('Found '.. FindCharacters(str) .. ' matches.') -- Found 6 matches. --
This solution works properly as intended, but I’m asking if there is any other way to do this or a specific function to do this more efficiently. Thanks for your time!