How can i fill a string with fill char ?

I was wondering is there a way to fill a string with a fill char like blankspace or . ?
i am trying to create an output which will displayed in a multiline textbox but the
strings have a diffrent length so to allign them i want to fill the sting all to smae length
so it looks nicer.

like

Value Name 1......Value 1
Demo Info...........Value 2

and so for...
AlexPonnathAsked:
Who is Participating?
 
ptakjaConnect With a Mentor Commented:
Try this routine:

    Private Function PadString(ByVal Text As String, ByVal FieldLength As Integer, ByVal FillChar As Char) As String
        Dim Pad As String
        For ii As Integer = 0 To FieldLength - Text.Length
            Pad &= FillChar.ToString
        Next
        Return Pad & Text

    End Function

Note that it only looks good for FIXED width fonts, such as Courier

Jeff
0
 
PaulHewsCommented:
Here you go

        Dim Test As String = New String("x"c, 50)
        MsgBox(Test)

        Dim Test1, Test2 As String
        'Format to exactly 50 char width
        Test1 = "Hello"
        Test2 = "World"
        Dim test3 As String = Test1 & New String(" "c, 50 - Test1.Length - Test2.Length) & Test2
        MsgBox(test3 & " length: " & test3.Length)
0
All Courses

From novice to tech pro — start learning today.