UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> TrimLeadingZero    


The Val() function will ignore leading zeroes and return the numerical value of a string. But what if you are dealing with an alphanumeric string and would like to preserve the other characters while trimming the leading zeroes?

' TrimLeadingZero
' http://www.utteraccess.com/wiki/TrimLeadingZero
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2010-09-11                    This function uses recursion to trim the leading zeroes and returns the rest of the string.
Public Function TrimLZ(ByVal strLZ As String) As String

If Left(strLZ, 1) = "0" Then
   TrimLZ = TrimLZ(Mid(strLZ, 2))
   TrimLZ = strLZ
End If

End Function

Creative Commons License
TrimLeadingZero 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 5,463 times.  This page was last modified 09:06, 6 April 2011 by Jack Leach. Contributions by TheDBguy  Disclaimers