UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> LPad    

' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
' You are free to use this code in any application,
' provided this notice is left unchanged.
' REV  DATE                          DESCRIPTION
' 1.0  2010-Oct-3              initial release
' 1.1  2011-Apr-4              Optimized.
  'This function will left pad a string with a specified
  'character. It accepts a base string which is to be left padded with
  'characters, a character to be used as the pad character, and a
  'length which specifies the total length of the padded result.
Function Lpad(MyValue As String, MyPadCharacter As String, MyPaddedLength As Integer) As String

   If Len(MyValue) < MyPaddedLength And Len(MyPadCharacter) > 0 Then
       Lpad = Right(String(MyPaddedLength, MyPadCharacter) & MyValue, MyPaddedLength)
       Lpad = MyValue
   End If

End Function

LPad can be used when you are dealing with numeric text and needing to sort it into numeric order. Sorting Text demonstrates the use of LPad in a query.

See also RPad

Creative Commons License
LPad by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 13,840 times.  This page was last modified 08:51, 6 April 2011 by Jack Leach. Contributions by Brent Spaulding, Alan Greenwood and Glenn Lloyd  Disclaimers