using System.Linq; // ... string example = " Hi there! "; string trimmed = String.Concat(example.Where(c => !Char.IsWhiteSpace(c))); // Result: "Hithere!"