How to remove new line characters from a string in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "c\n" +
                       "c++\n" +
                       "c#\n" +
                       "java\n" +
                       "python\n";

            s = Regex.Replace(s, @"\n", " ");

            Console.WriteLine(s);
        }
    }
}


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

 



answered Jul 26, 2018 by avibootz
edited Jul 26, 2018 by avibootz

Related questions

1 answer 447 views
1 answer 190 views
190 views asked Aug 13, 2023 by avibootz
1 answer 230 views
230 views asked Aug 11, 2023 by avibootz
1 answer 320 views
1 answer 155 views
2 answers 291 views
...