Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to remove spaces from a string?

title explains it all, i want to get a objects name and then remove all spaces from it

2 answers

✓ Accepted answer

To remove spaces from a string, you can use gsub.

testStr = 'this  string has many        spaces'

-- Replace spaces with empty text
testStrTrimmed = testStr:gsub('%s+', '')

print(testStrTrimmed)
-- output: thisstringhasmanyspaces

-- This also works, same thing, different syntax
testStrTrimmed = string.gsub(testStr, '%s+', '')
print(testStrTrimmed)
-- output: thisstringhasmanyspaces

Hope this helps! :)

1 comment

0

thanks

    try this

name = object.Name
name:gsub("%s+", "")

This discussion is preserved as it was. New answers, comments, and votes are closed.