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

How would I go about replacing text?

Asked by 7 years ago

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

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

I believe it involves using gsub

local text = "I love bananas very much!"
text = string.gsub(text,"bananas","apples")
print(text)
0
Thank you that works! +1 upvote and answer accepted! SebbyTheGODKid 198 — 7y
0
Will this replace every instance of bananas, or just the first one it finds? SebbyTheGODKid 198 — 7y
0
It should replace them all. Thanks for the upvote! mattscy 3725 — 7y
Ad

Answer this question