Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove the first leading zero in a string

Status
Not open for further replies.

cyberbob2

Programmer
Nov 13, 2003
32
0
0
US
Hello,

I have a function which removes ALL leading zeros, but is there a way to remove only the FIRST leading zero? Any help would be greatly appreciated. Below is my function to remove ALL leading zeros.

Thanks in advance, KP

Public Function RemoveLeadingZeros( _
ByVal strValue) As String

' Test if there is at least 1 leading zero
If Left(strValue, 1) = "0" Then

Do While True 'fContinue 'And (intPosition <= intLen)

If Mid(strValue, 1, 1) = "0" Then
strValue = Replace(strValue, "0", "", 1, 1, vbTextCompare)
Else
' reached the first non-zero string
Exit Do
End If

Loop

Else
' Does not have a leading zero
End If

RemoveLeadingZeros = strValue

End Function


 
Simply this:
If Left(strValue, 1) = "0" Then strValue = Mid(strValue, 2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

If Left(strValue,1)=0 Then strValue= Right(strValue, Len(strValue)-1)
 
I think many others have faced the situation where PHV
is always faster and always correct. [purpleface]
 
He claims to be a unix sysadmin + informix dba + cobol and C developper and propably has established a physical connection to the system for himshelf!

MATRIX PHV RE-LOADED
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top