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

How do i remove a part of a text and have other questions?

Asked by 4 years ago

-- 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

0
The GetFullName() method of Instance returns the full pathway to the object. This has no relation in the case of extracting specific pieces of strings. For that, take a look at :sub() or furthermore dive into string manipulation more deeply, as this is what you’re looking for Ziffixture 6913 — 4y
0
If you’re talking about referencing workspace alone, you can actually just call it singularly without the game keyword Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There is a string manipulation function called gsub(), and it does exactly what you want.

string.gsub() has 3 parameters that require arguments:

  1. The string to perform manipulation on.
  2. The pattern to look for within the string.
  3. The string that will replace the pattern (if the pattern is found).

(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.

Ad

Answer this question