Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because <code>System.Windows.Controls.RichTextBox</code> does not have a property for <code>Text</code> to detect its value, you may detect its value using the following</p> <pre><code>string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; </code></pre> <p>Then, you may change <code>_Text</code> and post the new string using the following</p> <pre><code>_Text = _Text.Replace("pc", "Personal Computer"); if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) { new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; } </code></pre> <p>So, it'd look like this</p> <pre><code>string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; _Text = _Text.Replace("pc", "Personal Computer"); // Replace pc with Personal Computer if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) { new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; // Change the current text to _Text } </code></pre> <p><strong>Remark</strong>: Instead of using <code>Text.Replace("pc", "Personal Computer");</code> you may declare a <code>List&lt;String&gt;</code> in which you save the characters and its replacements</p> <p><strong>Example:</strong></p> <pre><code> List&lt;string&gt; _List = new List&lt;string&gt;(); private void richTextBox1_TextChanged(object sender, TextChangedEventArgs e) { string _Text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text; for (int count = 0; count &lt; _List.Count; count++) { string[] _Split = _List[count].Split(','); //Separate each string in _List[count] based on its index _Text = _Text.Replace(_Split[0], _Split[1]); //Replace the first index with the second index } if (_Text != new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text) { new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text = _Text; } } private void Window_Loaded(object sender, RoutedEventArgs e) { // The comma will be used to separate multiple items _List.Add("pc,Personal Computer"); _List.Add("sc,Star Craft"); } </code></pre> <p>Thanks, <br> I hope you find this helpful :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload