I’m trying to make a string filter out any number / special character, but I can’t really find what class/string thingy would do that.
I’ve tried looking all over google but have found nothing!
Heres an example of what I want to happen:
local String = "I want to 😀 filter this emoji out"
-- Magical Code That Filters Message Here
print(String)--Output wanted: "I want to filter this emoji out"
32-126
“str” is the string you are trying to filter. Accepts codes from the range of 32 to 126.
local mod = 0
for i = 1, str:len() do
i-=mod
local sub = str:sub(i,i):byte()
if math.clamp(sub, 32, 126)~=sub then
local str1, str2 = str:sub(1, i-1), str:sub(i+1, str:len())
str = str1..str2
mod+=1
end
end
local String = "I want to 😀 filter this emoji out"
String = string.gsub(String, "[^%a%s]", "")
String = string.gsub(String, " ", " ")
print(String) --I want to filter this emoji out
Thank you, except I realized it only subs the space if there is 3…
string.gsub(String, " ", " ")
This pattern replaces two whitespaces with one so I’m not sure what you mean but use the following if you want to substitute any number of consecutive whitespaces with a single one.