string str = "This is a test";
str = str.Replace(" ", String.Empty);
// Output: Thisisatest
string str = "C Sharp";
str = Regex.Replace(str, @"\s", "");
string trim = Regex.Replace( text, @"s", "" );
using System.Linq;
// ...
string example = " Hi there! ";
string trimmed = String.Concat(example.Where(c => !Char.IsWhiteSpace(c)));
// Result: "Hithere!"