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

How do I find and replace text inside a string?

This one's a bit hard to explain, but i'll try. Lets say that there's a GUI that says "I love cats!". how would a script automatically find the word "cats"? and how could it replace it with "my cat"? Note that this example isn't exactly what i'm trying to do with it, so string.sub(8,11) would be useless

1 answer

✓ Accepted answer

use string.find! use this for more information: https://developer.roblox.com/en-us/api-reference/lua-docs/string

local stringfind = "cats are awesome!"

if string.find(stringfind) then
    stringfind = "my cats are awesome!"
end

2 comments

1

To add on to this, use GSUB to "replace" strings. For example, local string = "hello there human!" string:gsub("there","you"))

0

upvoted comment

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