title: Trim() doesn't work with tables
body: <p>I had to <a href="https://superuser.com/q/1028319/4844">solve a little problem today</a> (trimming trailing whitespace in a MS Word document that the PDF converter had added to each and every cell), and I quickly found out that this isn't possible using the standard Word interface, so wrote a small VBA script:</p>
  
  <pre><code>Sub TrimCellSpaces()
      Dim itable As Table
      Dim C As Cell
      For Each itable In ThisDocument.Tables
          For Each C In itable.Range.Cells
              C.Range.Text = Trim(C.Range.Text)
          Next
      Next
  End Sub
  </code></pre>
  
  <p>I was surprised that not only did this fail to remove the trailing spaces, it even added paragraph markers at the end of each cell. So I tried a regex approach:</p>
  
  <pre><code>Sub TrimCellSpaces()
      Dim myRE As New RegExp
      Dim itable As Table
      Dim C As Cell
      myRE.Pattern = "\s+$"
      For Each itable In ThisDocument.Tables
          For Each C In itable.Range.Cells
              With myRE
                  C.Range.Text = .Replace(C.Range.Text, "")
              End With
          Next
      Next
  End Sub
  </code></pre>
  
  <p>Same result. I added a breakpoint, copied the value of <code>C.Range.Text</code> (before replacement) into a hex editor and found that it ended in the hex sequence <code>0D 0D 07</code> (<code>07</code> is the ASCII Bell character (!)). </p>
  
  <p>I changed the regex to <code>\s+(?!.*\w)</code>, and the script worked flawlessly. After the replace operation, the value of <code>C.Range.Text</code> ended only in <code>0D 07</code> (one <code>0D</code> fewer).</p>
  
  <p>I also tried this with a newly created table, not one generated by Word's PDF importer - same results.</p>
  
  <p>What's going on here? Is Word using <code>0D 0D 07</code> as an "end of cell" marker? Or is it <code>0D 07</code>? Why did <code>\s+</code> remove only one <code>0D</code>?</p>