Like it

Sunday, July 10, 2011

How to Write Padded (Formatted) Text File using VB.NET/C#

Writing Equi-Spaced Output using C# and VB.NET

Here is a small code to write a multiplication table.

For i1 As Integer = 1 To 20

Console.WriteLine(i1.ToString & " x 12 = " & (i1 * 12).ToString)

Next i1




Have you ever thought it would be better to have it properly aligned. Then use the Padding options (PadeLeft here) to format the output



Private Sub WritePaddedText() 
' Write a Padded Multiplication Table 
For i1 As Integer = 1 To 20 
Console.WriteLine(i1.ToString.PadLeft(2) & " x  12 = " & (i1 * 12).ToString.PadLeft(3))          Next i1      End Sub  




No comments:

Post a Comment