A Simple Question2

  • Thread starter Thread starter Niki Estner
  • Start date Start date
Hello again...

Try this:

int a = 1;
string s = a.ToString();
string s2 = s.PadLeft(8, '0');

The PadLeft() method aligns to the right the characters in your original
string and inserts in the left the specified character (in this case '0')
until the strings reaches the specified length (8).
This method is overloaded:

String.PadLeft(int totalWidth); // Inserts blank spaces
String.PadLeft(int totalWidth, char paddingChar); // Inserts the specified
char paddingChar

In the MSDN you can find the oposite, String.PadRight().

Bye...
 
int a = 1;
how to print out a like 00000001
if a++, print out like 00000002...0000xxxx

thank u
 
Back
Top