When should I use string.format() over string interpolation?

When to use string.format() and when to use string interpolation ?

String.format is only ever necessary when the string you’re formatting is pre-defined.
For example, when formatting my datastore names I use string.format to format a pre-defined string, allowing the datastore name and version to be customized in a constants table:

constants = {
DATA_VERSION = "1",
DATA_NAME = "GameData_%s",
}

storeName = string.format(constants.DATA_NAME,constants.DATA_VERSION) -- GameData_1

However, when sending join messages I use string interpolation since I don’t need the message to be customizable:

`{plr.Name} has joined the game.}`
1 Like

I’d say they’re just interchangeable, you can use them both to achieve the same thing

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.