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

Finding a specific text in a string and replace it with something else, and keep the others alone?

Like for example, we have this SoundId of a Sound:

sound.SoundId = "rbxassetid://1337"

So I want the script to find the pattern "rbxassetid://" and replace it with "http://www.roblox.com/asset/?id=" using a script without changing the numbers.

So how do I do it?

1 answer

✓ Accepted answer

Hey anphu04,

You can easily replace patterns using string.gsub(), here let me show you an example below:

####Script

local string_with_pattern = "rbxassetid://1337";
local pattern = "rbxassetid://";

string_with_pattern = string.gsub(string_with_pattern, pattern, "http://www.roblox.com/asset/?id=");

###Now if you print string_with_pattern, it should print:

http://www.roblox.com/asset/?id=1337

##Well, I hope I helped and have a nice day.

###~~ KingLoneCat

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