Find and Replace rich text without losing formatting

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

Hello,

Does anyone know how to implement find and replace in a
RichTextBox in a way that does not lose the text
formatting?

As a first attempt I tried rtb.Rtf.Replace(sFindText,
sReplaceText) , but that's no good since .Rtf includes all
the formatting codes, and .Replace will change richtext
codes that shouldn't be changed.

I know I can't set the .Text or .SelectedText properties
of the RichTextBox because that would kill the formatting.

Any ideas or examples? Thanks!
Kevin
 
It looks like the answer might have something to do with
this code:

rtb.Find(sFindText)
rtb.SelectedText = sReplaceText

To replace all I'll loop through the text as long as Find
does not return -1.

I found a good example of how to do find and replace in
the vbCity.com forums at
http://vbcity.com/forums/topic.asp?tid=25133

Thanks,
Kevin
 
Back
Top