Would it be possible to filter out a certain word in a string of text?

I want to achieve a simple system where I have a table of words which I want to filter next up I want to search for these words in a string of text once found replace them with hashtags and then be able to print out the edited version of the text. I am not asking for anyone to create an entire system for me, I am asking if such a thing is possible and if so which function would I need to use or how would I be able to make this possible?

And yes, I do know I could filter the entire string using roblox’s textchatservice which I think already has a FilterString function, however let’s not lie to ourselves here we all know how the roblox chat filter system can sometimes just not work properly for example if you type a lot of numbers they get filtered.

look into string.gsub() might be what your looking for.

local filterTable = {"badword"} --replace with the words you want to filter

function filterString(str: string): string
	for _,f in filterTable do
		str = str:gsub(f,string.rep('#',f:len()))
	end
	return str
end

Yes, that would appear to be exactly what im looking for. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.