Skip to main content

Filter out all characters that are NOT digits ([0-9]) from the string.

// 
// Filter out all characters that are NOT digits ([0-9]) from the string.
// 
public static string FilterDigits (string str)
{
	if (string.IsNullOrEmpty(str)) return str;

	return Regex.Replace(str, @"[^\d]", "");
}