Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleLeft or right pad a string with a character
Keywordspad, fill
CategoriesStrings
 
To pad on the left, use the String function to make a string of the pad character that is as long as you want the result to be. Add this padding to the left of the original value. Then use Right$ to trim the result to the desired length.

To pad on the right, add the pad string to the right of the original value and use Left$ to trim the result.

 
Private Sub cmdPad_Click()
Dim value As String
Dim pad_text As String
Dim length As Integer

    value = txtString.Text
    pad_text = txtPad.Text
    length = CInt(txtLength.Text)

    If optSide(0).value Then
        ' Pad on left.
        txtResult.Text = Right$( _
            String(length, pad_text) & value, length)
    Else
        ' Pad on right.
        txtResult.Text = Left$( _
            value & String(length, pad_text), length)
    End If
End Sub
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated