Это удобно делать при помощи регулярок.
Проект приатачен
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, RegExpr, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Memo2: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm} {$O-} procedure TForm1.Button1Click(Sender: TObject); var r : TRegExpr; i, lastPos : integer;
begin r := TRegExpr.Create; r.ModifierS := true; r.ModifierM := true; r.Expression := '[^\s]+ing\s'; r.SpaceChars := r.SpaceChars + '.,:;()?!#10#13'; i := 0; lastPos := 1; if r.Exec(Memo1.Text) then while (r.MatchPos[i] <> -1) do Begin Memo2.Text := Memo2.Text + copy(Memo1.Text, lastPos, r.MatchPos[i] + r.MatchLen[i] - lastPos - 4) + 'ed' + Memo1.Text[r.MatchPos[i] + r.MatchLen[i]-1]; lastPos := r.MatchPos[i] + r.MatchLen[i]; if not r.ExecNext then Begin Memo2.Text := Memo2.Text + copy(Memo1.Text, lastPos, Length(Memo1.Text) - lastPos - 1);
break; end; end; end;
end.
|
|