function Search_And_Replace(RichEdit: TRichEdit; SearchText, ReplaceText: string): boolean; var startpos, position, endpos: integer; begin startpos := 0; with RichEdit do begin endpos := Length(RichEdit.Text); Lines.BeginUpdate; while FindText(SearchText, startpos, endpos, [stMatchCase])<>-1 do begin endpos := Length(RichEdit.Text) - startpos; position := FindText(SearchText, startpos, endpos, [stMatchCase]); Inc(startpos, Length(SearchText)); SetFocus; SelStart := position; SelLength := Length(SearchText); richedit.clearselection; SelText := ReplaceText; end; Lines.EndUpdate; end; end;
procedure TForm1.BitBtn1Click(Sender: TObject); begin Search_And_Replace(Richedit1,'Eski Yazı','Yeni Yazı'); end;