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 350 views
1 answer 100 views
100 views asked Aug 13, 2023 by avibootz
1 answer 137 views
137 views asked Aug 11, 2023 by avibootz
1 answer 222 views
1 answer 92 views
2 answers 176 views
...