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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

Ad

Answer this question