// add directive at the top using System.Text.RegularExpressions; string numberOnly = Regex.Replace(s, "[^0-9.]", "")