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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top