First import the namespace System.Text.RegularExpressions;
C#
// Replace non-numeric characters
string str = "12d223*23#22";
string newStr = Regex.Replace(str, @"[^\d]", "");
// Displays 122232322
VB.NET
' Replace non-numeric characters
Dim str As String = "12d223*23#22"
Dim newStr As String = Regex.Replace(Str, "[^\d]", "")
' Displays 122232322
This was perfect - thanks for the great (and simple) post!
ReplyDeleteRegex.Replace has a speed problem, will be your slowest line on your code, use with caution.
ReplyDeleteTHANKS !!!!!
ReplyDelete