How to trim whitespace between characters

Use String.Replace to replace all white space with nothing.

eg

string newString = myString.Replace(" ", "");

If you want to keep one space between every word. You can do it this way as well:

string.Join(" ", inputText.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => x.Trim()));

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", "");

Tags:

C#

Whitespace