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

How to remove spaces from a string?

Asked by 5 years ago

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

2 answers

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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! :)

0
thanks 2sp00ky4y0u 2 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
    try this

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

Answer this question