Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can i fill a string with fill char ?

Posted on 2004-10-23
2
Medium Priority
?
190 Views
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.

like

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

and so for...
0
Comment
Question by:AlexPonnath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 2000 total points
ID: 12388456
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
 
LVL 38

Expert Comment

by:PaulHews
ID: 12388486
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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