unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure PrintTextStat(Text: string; ResultList: TStrings);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.PrintTextStat(Text: string; ResultList: TStrings);
var
TestList,StatList: TStringList;
i,ind: Integer;
PCount: Pointer;
begin
ResultList.Clear;
if (Length(Trim(Text)) < 1) then
begin
ResultList.Add('Пустая строчка блин!');
Exit;
end;
ResultList.Add('Разбираем текст:');
ResultList.Add('"'+Trim(Text)+'"');
ResultList.Add('');
for i := 1 to Length(Text) do
begin
if (Text[i] in [' ','.',',','!','?',':',';','-']) then
Text[i] := #13;
end;
TestList := TStringList.Create;
TestList.Sorted := False;
TestList.Text := Text;
StatList := TStringList.Create;
StatList.Sorted := True;
StatList.Duplicates := dupIgnore;
for i := 0 to TestList.Count-1 do
begin
TestList[i] := AnsiLowerCase(Trim(TestList[i]));
if (TestList[i] = '') then Continue;
ind := StatList.Add(TestList[i]);
PCount := StatList.Objects[ind];
Inc(Integer(PCount));
StatList.Objects[ind] := PCount;
end;
if (StatList.Count < 1) then
begin
ResultList.Add('Блин! Ну пустая за строчка!');
Exit;
end;
ResultList.Add('');
ResultList.Add(Format('== Статистика слов (всего %d)==',[StatList.Count]));
for i := 0 to StatList.Count-1 do
begin
ResultList.Add(Format('%d) "%s" '#9#9+'встречается %d раз',[i+1,StatList[i],Integer(StatList.Objects[i])]));
end;
ResultList.Add('');
ResultList.Add('== конец фильма :-) ==');
StatList.Free;
TestList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintTextStat(Memo1.Text, Memo1.Lines);
end;
end.