String.math splitting

I wanted to know how to split a string and maintain string.match, what I mean is if you have the string Hello, and you with string.match you have ell, how would I get; H, ell, o in different string so I could do something with the H, the ell, and the o?

Could you elaborate more on what you need help with? It would be great if you could provide a clear example of input and expected output.

eg. “Hello World” → “Hello Roblox”

1 Like

something liek this
image
??
??

First we want to capture the content (if any).

image

Then we want insert RichText tags so that we can change only the portion of the text’s appearance. Since your example uses green, we will use it, to do that we need green in HEX format, for this example I chose #00FF00.

Then with RichText property set to true, Roblox engine renders it as we instructed it to.

To implement what we just described, we will create a function that will replace string based on match and replacement string. This can be done with string.gsub method.

local function highlightMatch(str: string, match: string)
	return string.gsub(str, match, [[<b><font color="#00FF00">]].. match.. "</font></b>")
end

Then we will create ScreenGui along with TextLabel that we will parent to the ScreenGui, once that is done, we will check the RichText property to true for the TextLabel as shown below.

image

We can then create LocalScript underneath the TextLabel, and we will put our function and the code below together.

script.Parent.Text = highlightMatch("Couch", "u")

The complete code should look something like this:

local function highlightMatch(str: string, match: string)
	return string.gsub(str, match, [[<b><font color="#00FF00">]].. match.. "</font></b>")
end

script.Parent.Text = highlightMatch("Couch", "u")

And once you play test, you should see the following:

image

1 Like

Like this?
local a, b, c = string.match(“Hello”, “(.+)(ell)(.+)”)