简体   繁体   中英

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!

This is one way of doing it:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM