en
Home About project

Replace multiple spaces in a string to single space with C#

If you need to replace multiple spaces (double spaces) in a string to single space with C# you can use next string method:

  • public string Replace(string oldValue, string newValue)

Replace - returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.

To replace multiple spaces to single space using C# see example:

    myString = Regex.Replace(myString, " {2,}", " ");