How to convert all whitespace in a string to a single space in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            string s = "c c++\n\t c# \n\rjava \rphp \tpython";
 
            s = Regex.Replace(s, @"\s+", " ");

            Console.WriteLine(s);
        }
    }
}


/*
run:
    
c c++ c# java php python
  
*/

 



answered Aug 26, 2018 by avibootz

Related questions

...