title: RichTextBox Silverlight Selected text replacement
body: <p>Ok, I have a class that uses inheritance of Richtextbox.</p>
  
  <ul>
  <li>INPUT:</li>
  </ul>
  
  <p>I need to get the selected text from a RichTextBox and replace it with some tags, I mean:</p>
  
  <pre><code>A sample text to replace but only the selected sample word
  </code></pre>
  
  <p>And I select "sample" and click a button to transform it to:</p>
  
  <pre><code>A &lt;A&gt;sample&lt;/A&gt; text to replace but only the selected sample word
  </code></pre>
  
  <p>The code for the replace that I been using is:</p>
  
  <pre><code>string selected = this.Selection.Text.Trim();
  
              if (selected.Length &gt; 0)
              {
                  this.Html = this.FormatedText.Replace(selected, string.Format("&lt;{0}&gt;{1}&lt;/{0}&gt;", tagName, selected));
              }
  </code></pre>
  
  <p>Html and FormatedText are attributes of my class</p>
  
  <p>The problem is that the RichTextBox.selection.text gets sample and if I try to use string.replace all the sample words will be marked, not only the selected one.</p>
  
  <ul>
  <li>NEEDS:</li>
  </ul>
  
  <p>¿How can I get the selected word and the initial position of the selected word in the original text and then get all the text in my RichTextBox with the new insertions?</p>