How to extract numbers from string

Posted by: Sushila Patels Weblog, on 04 Aug 2006 | View original | Bookmarked: 0 time(s)

VB.NET

Shared Function ExtractNumbers(ByVal expr As String) As String
 Return String.Join(Nothing, System.Text.RegularExpressions.Regex.Split(expr, "[^\d]"))
End Function

C#

static string ExtractNumbers(string expr)
{
 return string.Join(null,System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));
}

Call the function as follows

VB.NET

Response.Write (ExtractNumbers("12EFR77"))

C# 

Response.Write (ExtractNumbers("12EFR77"));

 

Share this post: Email it! | bookmark it! | digg it! | reddit!

Category: Regex | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 33459 | Hits: 178

Similar Posts

  • Postgresql - Day 2 more
  • Private Extension Methods more
  • Lookbehind in Regex searches more
  • Filtering with string parameter that allows free user input more
  • Custom Panels in Silverlight/WPF Part 4: Virtualization more
  • LINQ Tip of the week: System.String support more
  • How to install and configure Visual Studio Team Explorer more
  • ASP.NET disk-based caching more
  • From DB to DataGrid So Many Choices! more
  • Important Entity Framework Query Improvements for .NET 4.0 more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD