How can I replace multiple spaces in a string with only one space in C#?
Example:
1 2 3 4 5
would be:
1 2 3 4 5
How can I replace multiple spaces in a string with only one space in C#?
Example:
1 2 3 4 5
would be:
1 2 3 4 5
Use the regex pattern
I just wrote a new
Join
that I like, so I thought I'd re-answer, with it:One of the cool things about this is that it work with collections that aren't strings, by calling ToString() on the elements. Usage is still the same:
You can simply do this in one line solution!
You can choose other brackets (or even other characters) if you like.
Without using regular expressions:
OK to use on short strings, but will perform badly on long strings with lots of spaces.
I can remove whitespaces with this