Search this blog

Tuesday, June 2, 2009

Extract numbers from string in .NET

Following Method helps to Extract the number from a string variable

C# Code:

static string ExtractNumbers(string expr)

{

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

}

VB.NET Code:

Shared Function ExtractNumbers(ByVal expr As String) As String

Return String.Join(Nothing, System.Text.RegularExpressions.Regex.Split(expr, "[^\d]"))

End Function

No comments:

Post a Comment