Держи)
Для работы алгоритма, требуется мемо, листбокс и кнопка.
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
cnts:array of integer;
i,n:integer;
w:String;
begin
w:='';
SetLength(cnts,0);
with ListBox1.Items do
begin
ListBox1.Clear;
BeginUpdate;
for i:=1 to Length(Memo1.Text) do
if Memo1.Text[i] in [' ',',','.',#10,#13] then
begin
if (Length(w)>1) and (w[1]=w[Length(w)]) then
begin
n:=IndexOf(w);
if n <> -1 then cnts[n]:=cnts[n]+1
else
begin
Add(w);
SetLength(cnts,Length(cnts)+1);
cnts[high(cnts)]:=1;
end;
end;
w:='';
end
else w:=w+Memo1.Text[i];
for i:=Low(cnts) to high(cnts) do
Strings[i]:=Strings[i]+' : '+IntToStr(cnts[i]);
SetLength(cnts,0);
EndUpdate;
end;
end;