Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

The empty text in this string isn't getting removed. Also, how to resolve this?

Asked by 6 years ago

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!

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
6 years ago
Edited 6 years ago

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.

Ad

Answer this question