Removing Spaces from a String

If I have a variable which is a string, for example “Roblox is cool” and I want to remove the spaces in it, probably using string manipulation, is there a way for me to convert a string like that into “Robloxiscool”?

Basically how would I go about removing spaces from string values?
Examples of desired changes:
“Nice Game” → “NiceGame”
“Wow Cool Game” → “WowCoolGame”

7 Likes
local function removespaces(str)
    return str:gsub(" ","")
end

Would something like this work?

27 Likes

Seems to work, thanks!

[I need 30 characters]

3 Likes

Alternative


Alternatively, you can choose directly on variable if you don’t want a function:

str = str:gsub("%s+", "")
-- or --
str = string.gsub(str, "%s+", "")
21 Likes