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

What does the format method do?

Asked by
Thetacah 712 Moderation Voter
9 years ago

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

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

Ad
Log in to vote
0
Answered by 9 years ago

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. 

Answer this question