How would I take away the space in a string?

Hello! I am wondering how to take away a space in the name of an object. For example, an object named “Example Object” it(function/feature) would find and delete the space to turn it into “ExampleObject” Does roblox have a built in feature I could use to do this? If not how would I make a function that returns the string without spaces.

Thanks in advance!

You would use string patterns and string.gsub.

local str = "My Text"
local strWithoutSpace = string.gsub(str, "%s+", "")
-- replaces all characters matching the "%s+" pattern with ""

print(strWithoutSpace) -- prints "MyText"
1 Like

It works perfectly! Thank you!!

You wouldn’t need the + modifier in this case as you’re matching all whitespace characters anyway.