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 129 views
1 answer 137 views
2 answers 220 views
1 answer 164 views
1 answer 120 views
1 answer 114 views
...