Using String Format?

How are you suppose to use the first argument of




The first argument to string.format is the “description” as described at the bottom of this article:

It is how you are formatting the string.

print(string.format(“pi = %.4f”, PI))
–> pi = 3.1416 d = 5; m = 11; y = 1990

print(string.format("%02d/%02d/%04d", d, m, y))
–> 05/11/1990 tag, title = “h1”, “a title”

print(string.format("<%s>%s</%s>", tag, title, tag))
–> <h1>a title</h1>


Is it the same as the string pattern for string.match?

This here holds what you need, for the most part. I learned this just yesterday actually and I’m pretty giddy about it. These patterns and whatnot are what you use in conjunction with various methods from the string library.

1 Like


you broke it!


n-no not me dont look at me


Page doesnt exist.

Got another source?

what would in “”%2d:%02d"" mean in

string.format("%2d:%02d", minute, second)

then? I cant find that on the page

1 Like

FYI, these are called “format strings” and are 100% unrelated to Lua’s variation of regex.

string.format just delegates to C’s sprintf, so you can look at C documentation/tutorials.

@Fm_Trick’s link doesn’t point to the right topic.


Is it the same as the string pattern for string.match?

To reiterate, absolutely not. You will just confuse yourself if you try to relate them. They have loose similarities, in that they use the % character a lot, but not much beyond that.

The code examples i posted were from the link I posted, at the bottom.

Ah, yes, missed that you posted twice. The first link does go to a relevant page. This second one ( is not related to string.format at all.


Hold on, you were experiencing that problem too? I thought @Fm_Trick was just joking. My page is fine.

Probably just another Developer Hub problem, as usual.