DennyDotNet

Awesome ASP.NET C# and other cool coding stuff

About the author

Denny Ferrassoli
Developer at Casting Networks. MCP / .NET
E-mail me Send mail
Add to Technorati Favorites

Recent posts

Recent comments

Authors

Categories

None


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Return only numbers from a string

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.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:
Posted by SuperGhost on Sunday, April 22, 2007 4:00 PM
Permalink | Comments (0) | Post RSSRSS comment feed
Comments are closed