CodeItBetter Programming Another VB Programming Blog

How to return a Padded String with Blanks on Left

Posted on January 4, 2009
1
2
3
4
5
6
'String Manipulation - How to return return a Padded String with Blanks on Left
Option Explicit
 
Public Function PadL(ByVal strExpression As String, ByVal iWidth As Integer) As String
   PadL = Right(Space(iWidth) & RTrim(strExpression), iWidth)
End Function
Comments (2) Trackbacks (0)
  1. Thanks for this Function. For a specific application, I needed to add leading zeros to a numeric string and couldn’t believe MS Access doesn’t have a built-in function for this. I changed your function as follows for my purposes:

    Public Function PadL(ByVal strExpression As String, ByVal iWidth As Integer) As String
    PadL = String(iWidth – Len(strExpression), “0″) & RTrim(strExpression)
    End Function

    Simple and works like a champ.


Leave a comment


 

No trackbacks yet.