Replace non-numeric with empty string
Definitely regex: string CleanPhone(string phone) { Regex digitsOnly = new Regex(@”[^\d]”); return digitsOnly.Replace(phone, “”); } or within a class to avoid re-creating the regex all the time: private static Regex digitsOnly = new Regex(@”[^\d]”); public static string CleanPhone(string phone) { return digitsOnly.Replace(phone, “”); } Depending on your real-world inputs, you may want some additional logic … Read more