trim whitespace in c# code example Example: remove whitespace between string c# string str = "C Sharp"; str = Regex.Replace(str, @"\s", "");