Format string to a 3 digit number

前端 未结 9 1317
说谎
说谎 2020-12-15 02:07

Instead of doing this, I want to make use of string.format() to accomplish the same result:

if (myString.Length < 3)
{
    myString =  \"00\"         


        
相关标签:
9条回答
  • 2020-12-15 03:00
     string.Format("{0:000}", myString);
    
    0 讨论(0)
  • 2020-12-15 03:02

    It's called Padding:

    myString.PadLeft(3, '0')
    
    0 讨论(0)
  • 2020-12-15 03:08

    You can also do : string.Format("{0:D3}, 3);

    0 讨论(0)
提交回复
热议问题