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!
Burgonet
(Burgonet)
June 15, 2021, 4:49am
2
It is a shortened version of string.format(). Read here.
2 Likes
Soybeen
(Soybeen)
June 15, 2021, 4:51am
3
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!
Burgonet
(Burgonet)
June 15, 2021, 4:53am
6
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?")?
Soybeen
(Soybeen)
June 15, 2021, 4:59am
8
d = 5; m = 11; y = 1990
str = "%02d/%02d/%04d"
str:format(d, m, y)
--> 05/11/1990
1 Like
Burgonet
(Burgonet)
June 15, 2021, 5:01am
9
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