How to trim whitespace between characters

You could use String.Replace method

string str = "C Sharp";
str = str.Replace(" ", "");

or if you want to remove all whitespace characters (space, tabs, line breaks…)

string str = "C Sharp";
str = Regex.Replace(str, @"\s", "");

Leave a Comment