-- If I put Message = "Hello, how are you daddawd doing?")
--Is it possible to remove a part from a string If I wanted to remove the "daddawd"
Message:GetFullName("daddawd"):Remove()
--Is the best I have so far. Not working however
--Is it possible to remove a part from a string?
-- Also when using the GetFullName() function, why does it get the parent of the instance too For example game:GetFullName() >>>>> game workspace:GetFullName() >>>>> game.workspace
Why does it also get the game, which is the parent, instead of only the name"workspace"
-- Is there a way of getting the name of the "workspace" without having the parent before? which in this case, is game
Can you fully explain this
There is a string manipulation function called gsub()
, and it does exactly what you want.
string.gsub()
has 3 parameters that require arguments:
(If you call gsub()
right from the string, like str:gsub()
, you only need the last 2 arguments.)
So, in your example:
local Message = "Hello, how are you daddawd doing?"
All you need to do is replace daddawd
with whitespace:
local subbedMsg = Message:gsub("daddawd", "") print(subbedMsg) -- Prints "Hello, how are you doing?"
Further usage of gsub can be found here.
As for GetFullName()
, it returns the full name of the userdata. From game.Workspace
, it returns game Workspace
because game
and Workspace
are both part of the name, but the period that tells Roblox Lua that Workspace is a child of game is not. It is supposed to do this so that you can see an Instance's (or service's) ancestors and descendants.