I've been trying to solve this since yesterday, but I haven't been able to get any progress with this. What I'm trying to do here is remove the empty text on the left side of the string, this is what I got:
local msg = " ow" local function antispam() local mLen = string.len(msg) local b local a = 1 while true do b = string.sub(msg,a,a) if b == " " then print("'"..b.."' is empty. Place#"..a) msg = string.sub(msg,2) -- This isn't doing anything for some reason, it keeps the text the same. mLen = string.len(msg) else print("'"..b.."' is not empty. Place#"..a) break end a = a + 1 end end antispam() -- This is supposed to remove the invisible text on the left side of the text, but it doesn't.
I appreciate the help if any comes, thanks!
Lua's string library has a .match function
, which might be helpful:
local spaces = " world another world " local noSpaces = spaces:match("%s*(.*)") print(noSpaces) -- prints "world another world "
Focus on this pattern string: "%s*(.*)"
%s*
indicates that we're trying to match zero or more instances of whitespace characters in the string (tab, spaces, newlines)
.*
indicates that we want to match zero or more of any character, and the parentheses ()
means that we specifically want to capture (return) whatever was matched by the pattern inside the parentheses.