interceptwind
interceptwind

Reputation: 675

How to remove a specific string from WPF RichTextBox?

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!

Upvotes: 7

Views: 1478

Answers (1)

Kris
Kris

Reputation: 1383

This is one way of doing it:

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

textRange.Text = textRange.Text.Replace("Text", "Document");

Upvotes: 7

Related Questions