Hello, I am currently trying too figure out how to prevent fully empty names for my save slot system.
Now I am stuck with how to detect if a message is only spaces.
Here is the code for the check so far. (I have removed most of the code since I would have too provide an entire place file of my full game)
local SlotName = “Slot Name Here”
if SlotName ~= “” then
print(SlotName)
end
if not SlotName:match("^%s*$") then
print(SlotName)
end
Since the ^ anchor matches at the beginning and the $ anchor at the end, and the * quantifier to match 0 or more occurrences of %s, which is a whitespace. This accounts for empty string too.
Couldn’t you just check if SlotName:match("%S")? Parsing the entire string when you’re just checking if there’s one non-space character seems like overkill.