How can i fill a string with fill char ?

Posted on 2004-10-23
Last Modified: 2010-04-23
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.


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

and so for...
Question by:AlexPonnath
    LVL 14

    Accepted Solution

    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
            Return Pad & Text

        End Function

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

    LVL 38

    Expert Comment

    Here you go

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

            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)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    Suggested Solutions

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now