Formatting Console.WriteLine
-
Alright, I'm writing a bunch of integers to the screen of different lengths, followed by other numbers. Some are 3 digits long, some are five digits long, and the maximum is about 6 digits long. If the number is less than 6 digits long, I want it to write extra spaces after the number, to make it 6 total characters, before displaying more data. Etc. How do I do this? Thanks, As Always.
-
Alright, I'm writing a bunch of integers to the screen of different lengths, followed by other numbers. Some are 3 digits long, some are five digits long, and the maximum is about 6 digits long. If the number is less than 6 digits long, I want it to write extra spaces after the number, to make it 6 total characters, before displaying more data. Etc. How do I do this? Thanks, As Always.
You should take a look at the Composite Formatting article on MSDN. It shows you the ins and outs of the process. For your immediate satisfaction, though, try this:
String.Format( "{0,-6} {1,-6} {2,-6}", 7, 3.14, 0.5 );
"we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty -- modified at 19:58 Thursday 24th November, 2005