The answer is very simple, just a line of code: string outputString = Regex.Replace(inputString, @"\s", string.Empty);