String format in C#

Hi,

im having a problem , i have made some application which should write like this this:

1 4 4 2 5     2  dice are dead this roll. The score for this roll is 9
1 4 2          1 die is dead this roll. The score for this roll is 5
2 2             2 dice are dead this roll. The score for this roll is 0

i have written Console.Write(" Number of dead dice in this role: " + deadDice + "."); but now i have a problem because it writes it like this

 1 4 4 2 5     2 dice are dead this roll. The score for this roll is 9
1 4 2         1 die is dead this roll. The score for this roll is 5
2 2           2 dice are dead this roll. The score for this roll is 0

i have to make the "X dice are dead this roll......" to be under the last line exactly but it moves every time that a num is deleted.   can you please explain me how can i do it?  thanks.


JetixilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Expert1701Commented:
You can use the String.PadLeft and String.PadRight methods to format your output.  If you can list your code where it prints the "1 4 4 2 5     2  dice are dead this roll. The score for this roll is 9", I will show you how to adjust it.
0
cookreCommented:
This is an exceptionally popular page on string formatting in c#:
http://blog.stevex.net/index.php/string-formatting-in-csharp/

Look for the term 'alignment' to learn how to do right alignment.
0
jarwCommented:
The code sample below might get you going in the right direction. The part to focus on is that the "-10" is telling it to format the first string such that it allows room for 10 characters and the text should be left aligned.
/* The output of this code is:
1 2 3 4   Testing...
1 2 3     Testing...
1 2       Testing...
1         Testing...
*/
Console.WriteLine("{0,-10}{1}", "1 2 3 4", "Testing...");
Console.WriteLine("{0,-10}{1}", "1 2 3", "Testing...");
Console.WriteLine("{0,-10}{1}", "1 2", "Testing...");
Console.WriteLine("{0,-10}{1}", "1", "Testing...");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Expert1701Commented:
Jetixil, jarw gave you a very good example.  Did it answer your question?
0
Expert1701Commented:
My opinion is that the answer should be awarded to jarw.  He fully answered the original poster's question with a working example.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.