Denny.NET

I can haz ASP.NET goodness?

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

Disclaimer

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

© Copyright 2008

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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: ASP.NET
Posted by SuperGhost on Sunday, April 22, 2007 9:00 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading