title: Remove hidden characters in WPF rich text box
body: <p>(Since this question has not been getting any answers, I've re-worded it)</p>
  
  <p>In my application, I have a dialog that holds a Rich Text Box, the box is filled with a Tweet gathered from Twitter.  Using the tweet entities I format the tweet to have in-line hyperlinks to links in the tweet, mentions, and hashtags.  However, the hyperlinks are never positioned correctly; always being 2 or 3 characters too soon and too far.</p>
  
  <p>This is the code I use to set the text in the Rich Text Box:</p>
  
  <pre><code>TweetText.Document.ContentEnd.InsertTextInRun(Status.Text)
  Dim FlowDocument As FlowDocument = TweetText.Document
  If LinkEntity.Count &gt; 0 Then
              For Each Entity As Entities.TwitterUrlEntity In LinkEntity
                  Dim Start As TextPointer = FlowDocument.ContentStart
                  Dim StartPosition As TextPointer
                  Dim EndPosition As TextPointer
                  If Entity.StartIndex = 0 Then
                      StartPosition = Start.GetPositionAtOffset(Entity.StartIndex)
                  Else
                      StartPosition = Start.GetPositionAtOffset(Entity.StartIndex)
                  End If
                  EndPosition = Start.GetPositionAtOffset(Entity.StartIndex + Entity.DisplayUrl.Length, LogicalDirection.Backward)
                  Dim h As New Hyperlink(StartPosition, EndPosition)
                  AddHandler h.MouseLeftButtonDown, AddressOf Hyperclick_Link
                  h.NavigateUri = New Uri(Entity.Url)
                  h.Cursor = Cursors.Hand
              Next
          End If
  'I have the other entities here, they have very similar code'
  TweetText.Document = FlowDocument
  </code></pre>
  
  <p>This is my Rich Text Box XAML:</p>
  
  <pre><code>&lt;RichTextBox Name="TweetText" Margin="5" FontSize="14" BorderThickness="0" IsReadOnly="True" /&gt;
  </code></pre>
  
  <p>This is the output:</p>
  
  <p><img src="https://i.stack.imgur.com/t01An.png" alt="The problem!"></p>
  
  <p>The tweet entity has proper indexes for each entity, but I do think the Rich Text Box has hidden characters that are causing this offset.</p>