Jump to content

string formatting


IIYAMA

Recommended Posts

  • Moderators
Posted
local theString = tostring(2) 
if string.len(theString) == 1 then 
 theString = 0 .. theString 
end  
  
print(theString) 

Does anybody knows how to do this shorter?

So if there is one character, it will have a zero at front.

  
So: 
01 
02 
03 
04 
05 
06 
07 
08 
09 
10-- 2 characters. 
11 
12 
etc. 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

Thank you very much, I am not very good with string formats. :)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

ah, thank you very much again.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...