Here is a function I created some time ago to strip everything but numbers
out of a string. We used this to canonicalize SSN's. You could get the same
results using a Regular Expression and its respective Replace method.
Function
numbersOnly(ByVal
text As
String)
As
String
Dim
nums As
New
StringBuilder
For
Each
n As
Char
In
text
If Char.IsNumber(n)
Then
nums.Append(n)
End If
Next
Return
nums.ToString()
End
Function
Testing the function with: 0-123-456-789 will return:
0123456789.