title: C# - Parse/Format a .txt file
body: <p>So I have some .txt files that have been formatted in a way that I do not like. I want to read the file and reformat it by a click of a button (or 2) in my GUI. Also, I would like to be able resave the file with many options with a click of another button. Also, if it is possible I would like to have the original file be displayed in a rich text box on the left side of my GUI, and once the format button is clicked it will display the new text on the right side of my GUI in a seperate rich text box.</p>
  
  <p>So I currently have a functioning "Open File" button, "Save File" button, and "Clear Text" button. However, I need a "Format Text" button (unless we can combine the open file button and the format text button into just one button!)...</p>
  
  <p>Here is what the file will look like when it comes in.
  <a href="http://i.stack.imgur.com/mlSMm.png" rel="nofollow">http://i.stack.imgur.com/mlSMm.png</a></p>
  
  <p>And this is what I want it to look like when I click format.
  <a href="http://i.stack.imgur.com/1IzKF.png" rel="nofollow">http://i.stack.imgur.com/1IzKF.png</a></p>
  
  <p>I also have a GUI that I have made and to open and save the file I have the following code:</p>
  
  <pre><code>    private void openFileButton_Click(object sender, EventArgs e)
      {
         OpenFileDialog openFile = new OpenFileDialog();
         openFile.DefaultExt = "*.txt";
         openFile.Filter = ".txt Files|*.txt";
         openFile.InitialDirectory = "C:\\";
         openFile.RestoreDirectory = true;
  
         try
         {
            if(openFile.ShowDialog() == DialogResult.OK &amp;&amp; openFile.FileName.Length &gt; 0)
            {
            openedTextRichTextBox.LoadFile(openFile.FileName, RichTextBoxStreamType.PlainText);
            }
            else
               throw new FileNotFoundException();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
      }
  
      private void saveFileButton_Click(object sender, EventArgs e)
      {
         SaveFileDialog saveFile = new SaveFileDialog();
         saveFile.DefaultExt = "*.txt";
         saveFile.Filter = ".txt Files|*.txt";
         saveFile.InitialDirectory = "C:\\";
         saveFile.RestoreDirectory = true;
  
         try
         {
            if(saveFile.ShowDialog() == DialogResult.OK &amp;&amp; saveFile.FileName.Length &gt; 0)
            {
            formattedTextRichTextBox.LoadFile(saveFile.FileName, RichTextBoxStreamType.PlainText);
            }
            else
               throw new FileNotFoundException();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
      }
  </code></pre>
  
  <p>Okay so the actual question is:</p>
  
  <p>How do I format the incoming txt file to delete everything except for (not including) the columns labeled "level", "number ref", "component item", "description". This meaning, everything under the "---" until I hit another "---". After I hit another "---" I need to grab the same columns as above. Does this make more sense? The example of how I want it to look is in the second link.</p>