I have strings like this:
"This______is_a____string."
(The "_" symbolizes spaces.)
I want to turn all the multiple spaces into only one. Are there any functions in C# that can do this?
var s = "This is a string with multiple white space";
Regex.Replace(s, @"\s+", " "); // "This is a string with multiple white space"
Regex r = new Regex(@"\s+");
string stripped = r.Replace("Too many spaces", " ");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With