What does :format() do?

Hello there! So, while learning scripting I found this :format. I’ve literally no idea of how to use it. I’ve seen it inside of TopBarPlus v2 and some other places. It would be helpful if anybody could make me understand how it works.

Thanks!

  • AridTheDev

It is a shortened version of string.format(). Read here.

2 Likes

If you found that documentation a little too bare, check out what lua.org has to say about it here: The String Library

1 Like

Are they the same thing? (characters limit)

Okay thanks! I’ll check both of them out!

Yes, they are the exact same, but you use :format() directly on a string.

1 Like

You mean something like

:format("Hello, how are you?")?

d = 5; m = 11; y = 1990
str = "%02d/%02d/%04d"
str:format(d, m, y)
--> 05/11/1990
1 Like

Like this

local str = "This is a %s string"
print(str:format("test")) -- This is a test string

as opposed to…

string.format("This is a %s string", "test")
2 Likes

Ohh now I get it!

Thanks to @Burgonet and @Soybeen!

1 Like