Reading — step 1 of 5
Learn
~1 min readStrings
string.format works like C's printf:
print(string.format("%d + %d = %d", 2, 3, 5))
print(string.format("%.2f", math.pi)) -- 3.14
print(string.format("%-10s|%5d", "hi", 42)) -- left-pad string, right-pad number
Common specifiers:
%dinteger%ffloat (%.2ffor 2 decimals)%sstring%xhex%qquoted string (escaped for re-parsing by Lua)
Unlike Python f-strings, Lua's %s will call tostring() on whatever you pass — handy for debugging.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…