Replacing Text in a String

How can I replace the following: "[Test1][Test2][Test3]"

  • Test1 being “Cat”
  • Test2 being “Dog”
  • Test3 being “Cow”

Here’s the catch, the string could be just [Test1][Test3] at times or even nothing
How can I accomplish replacing them with the correct replacement?

use string.gsub for that string | Roblox Creator Documentation

local String = "[Test1][Test2][Test3]"
local Replacements = {
	["Test1"] = "Cat",
	["Test2"] = "Dog",
	["Test3"] = "Cow"

for i,v in pairs(Replacements) do 
	String = string.gsub(String, i, v)

print(String) -->> [Cat][Dog][Cow]
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.