Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,959 questions

51,901 answers

573 users

How to split a string by empty line in C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        string str = "line 1.\r\n\r\nline 2.\r\n\r\nline 3.\r\nline 4.\r\nline 5.";
        public Form1()
        {
            InitializeComponent();
            label1.Text = str;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] lines = str.Split(new[] { Environment.NewLine + Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            label1.Text += Environment.NewLine + Environment.NewLine;

            foreach (string s in lines)
            {
                label1.Text += s;
            }
        }
    }
}




/*
 * run:
 *
 * line 1.
 * 
 * line 2.
 * 
 * line 3.
 * 
 * line 4.
 * 
 * line 5.
 * 
 * line 1.line 2.line 3.
 * line 4.
 * line 5.
 * 
 */


 



answered Jul 31, 2023 by avibootz
edited Jul 31, 2023 by avibootz

Related questions

...