Reputation: 1150
I am creating a C# program that outputs text to a file. I want to align all information based of a set specification. For example, I want line#
to have 20 chars of space, message info
to have 25 chars of space. If the space is unused I want it to be empty spaces. I have searched everywhere and haven't been able to find anything to work.
I have included a basic example below. I used the periods for formatting in the post, I do not want to use them in my output.
Line #1.............Message Info #1 Line #15............Message Info #15 Line #534...........Message Info #534
Upvotes: 0
Views: 2517
Reputation: 23142
This is my go-to resource for string formatting in C#, which is essentially all you're doing:
http://blog.stevex.net/string-formatting-in-csharp/
Upvotes: 1
Reputation: 13628
Look here net format a string with fixed spaces
var line1 = String.Format("{0,20}", s);
Upvotes: 4