15 Sep 2011

C# Regex-Remove all non numeric characters from a string

 

using System.Text.RegularExpressions;
string newString = Regex.Replace(oldString, "[^.0-9]", "");
(If you don't want to allow the decimal delimiter in the final result, remove the . from the regular expression above).

string newString = Regex.Replace(oldString, "[^0-9]", "");

No comments:

Post a Comment