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

What does the format method do?

Hey guys, I was going through someones code, and I found this line of code. I've never used the format method, so, what would this sequence of code do?

w.Name = ("%s_Weld"):format(v.Name)

?

2 answers

It uses string patterns to substitute in text or anything that tostrings() to text passed to the format method as arguments to make a complete string.

It's an alternate to concatenation, basically, and is sometimes easier to read and smaller to write.

It's an alternative to concatenation, and in some cases, is easier to read. For example:

local myString = "Hello, my name is %s."

print(myString:format("David")) --'David' is substituted for the %s pattern

--OUTPUT: Hello, my name is David. 

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