I know I have to use string functions, but I just don’t know how to. I’m filtering strings within my textbox using TextService, and I’m using the string to initiate a search through a module on the server side. However, the #### I get sometimes are messing up the search, so what I want to do is to have it so if I had a random sentence typed up like so:
--Hey I'm bob #### lol I don't know it doesn't make sense
Then I can use string functions to get rid of the hashtags, leaving a fresh unfiltered string like so
--Hey I'm bob lol I don't know it doesn't make sense
I just need some guidance, because I don’t fully understand how to use these functions to achieve it.
You can use string.gsub to find and replace matches of a substring. For example if you wanted to remove all ‘#’ characters from a string you could do something like the following:
local string_with_hashtags = "Hey I'm bob #### lol I don't know it doesn't make sense"
local string_no_hashtags, removedCount = string.gsub(string_with_hashtags, "#", "")
--Looks for '#' substrings and replaces them with the empty string ("")
--string_no_hastags - has the new string with hashtag characters removed
--removedCount - int, signifying the number of occurrences found and replaced with the replace string