How to remove whitespace from a string in C#

1 Answer

0 votes
using System;
using System.Linq;

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

        s = String.Concat(s.Where(ch => !Char.IsWhiteSpace(ch)));
        
        Console.Write(s);
    }
}




/*
run:

c#c++cjava

*/

 



answered Jul 10, 2020 by avibootz

Related questions

...