Count Leading Zero of String

Hi, can anyone show me how to count leading zero of a string?
I have searched the KB but not exactly what I am looking for, just want a simple count result of the number of leading Zero of a string.
Strings randomly consist of min 5 characters or max of 15 characters, all numeric, no alphabet involved.

e.g.
04421000
Result = 1

001540045456001
Result = 2

000123450100124
Result: = 3

121001421000041
Result = 0

Thx
kay sooAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try a function like this:

Function getLeadingZeroCount(ByVal v As String) As Integer
    tmp = Trim(v)
    If tmp = "" Then
        getLeadingZeroCount = 0
    Else
        For i = 1 To Len(tmp)
            If Mid(tmp, i, 1) = "0" Then
                getLeadingZeroCount = getLeadingZeroCount + 1
            Else
                Exit Function
            End If
        Next i
    End If
End Function

Open in new window

0
mbizupCommented:
If you're just looking for a count of leading zeros, compare the length of the whole string to the length of the value of the string (leading zeros dropped):

msgbox "Number of Leading Zeros: " & len(s) - Len(cstr(val(s)))

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
@mbizup,

yup, a smart one
0
kay sooAuthor Commented:
Thx for the solutions fellas, I go for @mbizup cause I used an unbound field to keep the count.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.