Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I go about replacing text?

Title says it all, but basically I want something like:

-- My script
text = "I love bananas very much!"
-- And then have some code that changes "bananas" to "apples"
print(text) --> So it will say "I love apples very much!"

I'n not very good with string manipulation yet, so any help would be appreciated!

Thanks in advance, SebbyTheGODKid

1 answer

✓ Accepted answer

I believe it involves using gsub

local text = "I love bananas very much!"
text = string.gsub(text,"bananas","apples")
print(text)

3 comments

0

Thank you that works! +1 upvote and answer accepted!

0

Will this replace every instance of bananas, or just the first one it finds?

0

It should replace them all. Thanks for the upvote!

This discussion is preserved as it was. New answers, comments, and votes are closed.