Wednesday, February 19, 2020

How do I replace multiple spaces with a single space in C#?

Example:

1 2 3  4    5
would be:

1 2 3 4 5


Solution:-
RegexOptions options = RegexOptions.None;
Regex regex = new Regex("[ ]{2,}", options);     
tempo = regex.Replace(tempo, " ");


myString = Regex.Replace(myString, @"\s+", " ");

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...