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 175 views
175 views asked May 30, 2023 by avibootz
1 answer 154 views
154 views asked May 30, 2023 by avibootz
1 answer 116 views
3 answers 171 views
171 views asked May 30, 2023 by avibootz
1 answer 108 views
108 views asked May 30, 2023 by avibootz
1 answer 136 views
1 answer 105 views
...