To replace multiple spaces with a single space in C# or VB.Net
Below is the snippet if you want to replace multiple spaces in a string with only one space using Regular Expressions in C# / VB.NET
string myString = "a b c d e"; myString = Regex.Replace(myString, @"\s+", " ");
Dim myString As String myString = "a b c d e" myString = Regex.Replace(myString, "\s+", " ")
Output - “a b c d e” would be : “a b c d e”

It working Fine. Great !!!!