Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a specific string from WPF RichTextBox?

Tags:

c#

wpf

How do I remove a specific string from WPF RichTextBox (if the string exist)?

To rephrase my question, what is the WPF equivalent of the following WinForm RichTextBox version:

richTextBox1.Text = "aaabbbccc";
richTextBox1.Text = richTextBox1.Text.Replace("bbb", "");

Thanks!

like image 724
interceptwind Avatar asked Dec 15 '15 03:12

interceptwind


1 Answers

This is one way of doing it:

TextRange textRange = new TextRange(
    richTextBox.Document.ContentStart,
    richTextBox.Document.ContentEnd
);

textRange.Text = textRange.Text.Replace("Text", "Document");
like image 133
Kris Avatar answered Oct 30 '22 16:10

Kris