How to remove extra spaces from a string in C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main() {
        string s = "       c#     c  c++        java     ";

        s = s.Trim();
        s = Regex.Replace(s, @"\s+", " ");
        
        Console.Write(s);
    }
}



/*
run:

c# c c++ java

*/

 



answered Jun 15, 2020 by avibootz

Related questions

1 answer 168 views
1 answer 177 views
2 answers 277 views
1 answer 205 views
1 answer 159 views
1 answer 153 views
...