Reputation: 59
I looked through the website, couldn't find anything that specifically addressed the issue.
I have a console app that loops through, finds strings between 7-20 characters, plus date/time, plus a Flag, plus the file.
Console.Write("=========================================================================");
Console.WriteLine("Start time: " + DateTime.UtcNow);
Console.Write("=========================================================================");
Console.WriteLine("All times in UTC.");
Console.Write("=========================================================================");
Console.WriteLine(String.Format("{0,-8}{1,17}{2,37}{3,13}", "Time", "File:Offset", "F", "String"));
Console.Write("=========================================================================");
The problem is the string and filename+path can be varying length. The Output uses the same string format, but depending on the length of the filename, the formatting is off.
Is there a way to have the console write items starting at a fixed position everytime.
So Time starts at 0, file:offsett starts at 17, F starts at 37, and String starts at 40. That way it formats properly. Also, this may be a bit more advanced, but can it truncate anything that won't fit in the column?
Thanks!
Upvotes: 1
Views: 4029
Reputation: 115773
You could use the PadLeft
string function in c# to achieve what you want
more info here http://msdn.microsoft.com/en-us/library/system.string.padleft(v=vs.71).aspx
Upvotes: 1