print(string.find("hello there. I say hello. hello I say","hello"))
it will return the same thing as
print(string.find("hello there","hello"))
Is there a function that could return a table of the position of all the different "hello"s?
What are you attempting to achieve?
The end goal is colorful syntax highlighting ingame
What is the issue?
string.find only shows the first piece it finds, not all the pieces.
Solutions I’ve thought of:
I could loop through and replace each print temporarily with some strange unused character and then change it all back at the end, but that seems like a lot of work
local function findAll(str, sub)
local found = 0
local positions = {}
while(found)do
found = found + 1
found = str:find(sub, found)
table.insert(positions, found)
end
return positions
end
string.find has another parameter that will look for the substring you provide it starting at that position
ex: string.find(str, sub, 2) will never find the substring if it starts at position 1