title: Remove all HTML tags and do a carriage return on <BR> in C#
body: <p>I am creating a HTML to text parser. I need to remove all HTML elements and want to do a carriage return everytime there is a <code>&lt;BR&gt;</code> and then remove the <code>&lt;BR&gt;</code> as well after so there are no HTML tags left. I then want to parse the text for a certain string that is in the combobox. Thank you in advance for your help.</p>
  
  <pre><code>private void navigateWeb_Click(object sender, EventArgs e)
      {
  
          openFD.Title = "Select your configuration file";
          openFD.InitialDirectory = "C:";
          openFD.FileName = "";
          openFD.Filter = "Config File (*.cfg)|*.cfg|Text File (*.txt)|*.txt|All Files (*.*)|*.*";
          openFD.ShowDialog();
          MyURL = openFD.FileName;
          //Open and read file
          System.IO.StreamReader objReader;
          objReader = new System.IO.StreamReader(MyURL);
          richTextBox1.Text = objReader.ReadToEnd();
  
          var lines = File.ReadAllLines(MyURL)
              .Select(l =&gt; l.Trim())
              .Where(l =&gt; l.StartsWith(comboBox1.Text));
          textBox1.Text = String.Join(Environment.NewLine, lines);
  
  
      }
  </code></pre>
  
  <p><em><strong></em>**<em>*</em>**<em>*</em>***</strong><em>UPDATE</em><strong><em>*</em>**<em>*</em>*</strong>
  Here is the solution that got the job done:</p>
  
  <pre><code> public static string RemoveHTML(string text)
      {
          text = text.Replace("&amp;nbsp;", " ").Replace("&lt;br&gt;", "\n");
          var oRegEx = new System.Text.RegularExpressions.Regex("&lt;[^&gt;]+&gt;");
          return oRegEx.Replace(text, string.Empty);
  
      } 
  private void navigateWeb_Click(object sender, EventArgs e)
  {
  
      openFD.Title = "Enter URL in the box below";
      openFD.InitialDirectory = "C:";
      openFD.FileName = "http://msnconf/configtc.aspx?IP=10.6.64.200&amp;m=c";
      openFD.Filter = "HTTP://|*.*|Config File (*.cfg)|*.cfg|Text File (*.txt)|*.txt|All Files (*.*)|*.*";
  
  
  
      //openFD.ShowDialog();
      if (openFD.ShowDialog() == DialogResult.Cancel)
      {
          //MessageBox.Show("cancel button clicked");
      }
      else
      {
          MyURL = openFD.FileName;
  
          webBrowser1.Visible = true;
          richTextBox1.Visible = false;
          permitACL.Enabled = true;
  
  
          //webBrowser1.Navigate(new Uri(MyURL.SelectedItem.ToString()));
          webBrowser1.Navigate(MyURL);
          //Open and read file
          System.IO.StreamReader objReader;
          objReader = new System.IO.StreamReader(MyURL);
          richTextBox1.Text = objReader.ReadToEnd();
  
  
  
  
          //Read all lines of file
          //            String lines = objReader.ReadToEnd();
          String[] crString = { "&lt;BR&gt;&amp;nbsp;" };
          String[] aLines = richTextBox1.Text.Split(crString, StringSplitOptions.RemoveEmptyEntries);
          //            String[] lines = File.ReadAllLines(MyURL);
          String noHtml = String.Empty;
  
          for (int x = 0; x &lt; aLines.Length; x++)
          {
              if(permitACL.Checked)
              {
  
                  if (aLines[x].Contains("permit"))
              {
                  noHtml += (RemoveHTML(aLines[x]) + "\r\n");
              }
  
              }
  
              if (aLines[x].Contains(comboBox1.Text))
              {
                  noHtml += (RemoveHTML(aLines[x]) + "\r\n");
              }
          }
  
          //Find lines that match our text in the combobox
          //lines.Select(l =&gt; l.Trim());
          //.Where(l =&gt; l.StartsWith(comboBox1.Text));
  
  
  
          //Print results to textbox
          textBox1.Text = String.Join(Environment.NewLine, noHtml);
      }
  
  }
  </code></pre>