Windows Phone Developers

Wednesday, May 25, 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

See also :How to Create Equispaced Text File using VBA; Spacing in Text Files Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment