Difference between revisions of "Extract numbers from an alpha numeric string"

From CodeCodex

 
Line 1: Line 1:
 
==Implementations==
 
==Implementations==
 
===Visual Basic===
 
===Visual Basic===
 +
<pre>
 
Function OnlyNumbers(ByVal Str As String) As Long
 
Function OnlyNumbers(ByVal Str As String) As Long
 
   Dim i As Long, k As Long, j As Long
 
   Dim i As Long, k As Long, j As Long
Line 11: Line 12:
 
   OnlyNumbers= j
 
   OnlyNumbers= j
 
End Function
 
End Function
 
+
</pre>
 
[[Category:Visual Basic]]
 
[[Category:Visual Basic]]
 
[[Category:String]]
 
[[Category:String]]

Revision as of 19:05, 20 July 2006

Implementations

Visual Basic

Function OnlyNumbers(ByVal Str As String) As Long
  Dim i As Long, k As Long, j As Long
  For i = 0 To Len(Str)
    k = Mid(Str, i + 1, 1)
    If Not k >= 0 Or k <= 9 Then
      j = j + k
    End If
  Next
  OnlyNumbers= j
End Function