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 197 views
197 views asked May 30, 2023 by avibootz
1 answer 172 views
172 views asked May 30, 2023 by avibootz
1 answer 134 views
3 answers 198 views
198 views asked May 30, 2023 by avibootz
1 answer 120 views
120 views asked May 30, 2023 by avibootz
1 answer 153 views
1 answer 123 views
...