CodeItBetter Programming Another VB Programming Blog

How to Find First Numbers of String (along with alphas & decimals)

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'String Manipulation - How to Find First Numbers of String (along with alphas & decimals)
Public Function FindFirstNumAlpha(ByVal MyString As String)
    Dim NumFoundFlag As Boolean
    Dim Char As String
    Dim I As Integer, StartPos As Integer
    NumFoundFlag = False
    For I = 1 To Len(MyString)
        Char = Mid$(MyString, I, 1)
        If IsNumeric(Char) = True And NumFoundFlag = False Then
            NumFoundFlag = True
            StartPos = I
        ElseIf (IsNumeric(Char) = False And Char <> "." And (Asc(Char) < 65 Or Asc(Char) > 90) And _
                (Asc(Char) < 97 Or Asc(Char) > 122)) And NumFoundFlag = True Then
            GoTo ExitHere
        End If
    Next
 
ExitHere:
    FindFirstNumAlpha = Mid$(MyString, StartPos, I - StartPos)
End Function
 
'How can I use this function:
'Debug.Print FindFirstNumAlpha("asdfsdx8a.9a,4,59sdf04dfd80 ) d99 - dk98")
'will display 8a.9a
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.