How to split a string by newline in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string str = "c#\njava\nc\npython";
        
        string[] lines = str.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

        foreach (string line in lines) {
            Console.WriteLine(line);
        }
    }
}




/*
run:
 
c#
java
c
python
 
*/

 



answered May 30, 2023 by avibootz

Related questions

2 answers 184 views
184 views asked May 30, 2023 by avibootz
1 answer 163 views
163 views asked May 30, 2023 by avibootz
1 answer 123 views
3 answers 186 views
186 views asked May 30, 2023 by avibootz
1 answer 113 views
113 views asked May 30, 2023 by avibootz
1 answer 143 views
1 answer 113 views
...