Trivial string format question

  • Thread starter Thread starter WRH
  • Start date Start date
W

WRH

Hello
I am a C# newbie. I have an int that I want to convert to a fixed length
string
using leading zeros if necessary , ie int num = 0, string str =
num.ToString()
so that str is 0000 (eg, in C++ I would use str.Format("%4.4d",num)
Should be simple but I havent yet found out how to do it.
 
WRH said:
I am a C# newbie. I have an int that I want to convert to a fixed length
string
using leading zeros if necessary , ie int num = 0, string str =
num.ToString()
so that str is 0000 (eg, in C++ I would use str.Format("%4.4d",num)
Should be simple but I havent yet found out how to do it.

string x = num.ToString ("0000");
 
Back
Top