How to extract a number from alphanumeric text string?

Dim mystring, myLength
mystring = “abhikansh567st1239test”
myLength = Len(mystring)

For i = 1 To myLength
    If Asc(Mid(mystring, i, 1)) <> 32 Then
        If Asc(Mid(mystring, i, 1)) >= 48 And Asc(Mid(mystring, i, 1)) <= 57 Then
            myNumber = myNumber & Mid(mystring, i, 1)
        End If
    Else
        msgbox(“no numeric”)
    End If
Next
msgbox(myNumber)

6 thoughts on “How to extract a number from alphanumeric text string?”

  1. str = "abhikansh567st1239test"
    Set regEx = New RegExp
    regEx.pattern="d+"
    regEx.Global = True
    Set obj = regEx.Execute(str)

    For i=0 to obj.count-1

    msgbox obj.item(i)

    Next

  2. Hi by using Regular expressions also we can extract a number from alphanumeric text string.i any one have doubts please let me know

    Set r=new regexp
    r.pattern="[0-9]+"
    r.global=true
    x="koteswararao423"
    Set y=r.execute(x)
    For each z in y
    msgbox z

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top