split textBox1.text into paragraphs

Please can someone help me with the regex.split expression I need:

to be able to split the string of text in textBox1 into paragraphs

where a blank line between lines of text is the delimiter.



Answer this question

split textBox1.text into paragraphs

  • LORD ORION

    If i understand what your saying correctly thiers this::

    using (StreamReader sr = new StreamReader(ofd.FileName)) this is using a OpenFileDialog "ofd"

    this.listView1.Items.Add(new ListViewItem(sr.ReadLine().Split(':'))); // Adding a Semi Colon example johndoe : 0123456

    than theirs::

    StreamWriter writer = File.CreateText("reminders.txt");

    writer.WriteLine("Dont forget its Mothers day");

    writer.WriteLine("Dont forget its Fathers day");

    write.WriteLine(" Happy Fathers Day");

    for (int i = 0; i < 10; i ++);

    writer.Write(i + " ");

    // insert a new line

    writer.WriteLine(writer.NewLine);

    //Closing automatically flushes

    writer.Close();

    Hope this gives you some idea's with what you needed...


  • Raymundo Chapa94595

    thanks but maybe I was not clear. The user enters some text into textBox1 in the form of paragraphs with 1 blank line between paragraphs.

    I would like to split the paragraphs and need help with the regex.split expression. I tried

    foreach (string strItem in Regex.Split(textBox1.Text, ("" + ("\n\n"))))

    {

    MessageBox.Show (strItem);

    }

    but this does not seem to work.


  • VectorR3

    Figured it out if anyone is interested

    Regex.Split(textBox1.Text, "\r\n\r\n")


  • split textBox1.text into paragraphs