title: Delete specific linebreaks with Word Interop
body: <p>i have Problems to delete some specific Linebreaks with word interop. It seems that the indexes of doc.Content.Text does not match with the ones of word..</p>
  
  <p>I need to delete all breaks which has no dot as previous character.</p>
  
  <p>With small documents it works, but only for about 3-5 breaks after that, the selected Range is not a pagebreak, anyone has an idea how to delete these breaks without range.select(start: start, end: end) or knows the problem?</p>
  
  <p><strong>for example i have following text:</strong></p>
  
  <p><em>US investigators who looked at a poll of 340,000 people found moods were no worse on Mondays than other working days, bar Friday.((break))</em></p>
  
  <p><em>People were happier as they approached the weekend, lending support for the concept of ((break to delete))</em></p>
  
  <p><em>"that Friday feeling".((break))</em></p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
  
          word.Visible = true;
  
          string document = @"C:\bin\Debug\123.doc";
  
          if (document != null)
          {
              Document doc = word.Documents.Open(document, ReadOnly: false, Visible: true);
              doc.Activate();
              string text = doc.Content.Text;
  
              int index = text.IndexOf("\r");
              int deletetCount = 0;
  
              while(index != -1)
              {
                  if (index != 0 &amp;&amp; text[index - 1] != '.')
                  {
                      int start = index + 1 - deletetCount;
                      int end = start + 1;
                      if (start &gt;= 0 &amp;&amp; end &gt;= 0 &amp;&amp; end &gt; start)
                      {
                          Range range = doc.Range(Start: start, End: end);
                          range.Select();
                          range.Delete();
                          deletetCount++;
                      }
                  }
  
                  index = text.IndexOf("\r", index + 1);
              }
          }
      }
  }
  </code></pre>