Script / Plugin to turn ("string"):format(...) to string.format("string", ...)?

Pretty much everything on the title, anyone has a command-line script for that? Not sure how to do that, I don’t understand the string library and everything, is that possible?

I always write my scripts with ("Time: %s"):format(time) instead of string.format("Time: %s", time) because in my opnion it looks better for most cases on which I’m using it.

And since it’s slower than string.format it would be great to have a little tool to just convert it;

1 Like

You can use a script which you would put inside the command bar.
Also made it work with variables.

local pattern = '%(([[%w+%p+%s+]+)%):format%(([%w+%p+%s+]+)%)'

for _, object in pairs(game:GetDescendants()) do
local success, result = pcall(function()
return object:IsA('BaseScript')
end)

if not success or not result then
continue
end

object.Source = string.gsub(object.Source, pattern, 'string.format(%1, %2)'
end
2 Likes

Hm, sadly it doesn’t seem to work, it turns it into this:

image

I’m pretty bad at patterns let me try to fix it.

Try using the updated version of the script.
(couldnt figure out how to get rid of the ()'s)

lol, it didn’t work either

image

and it adds a “string.format” in the first characters of the script for some reason

image

Probably because I did not add “%(” at the beginning of the pattern.

1 Like

Well it fixed that problem, but it still kind of doesn’t work properly;

image

I’ll leave you alone lol, it’s fine;

It’s fine, might be because of %s includes new lines too but I don’t know I’m on mobile at the moment.

1 Like