Einzelnen Beitrag anzeigen

Lisa.99

Registriert seit: 13. Feb 2017
21 Beiträge
 
#33

AW: Buchstabenhäufigkeit

  Alt 20. Feb 2017, 07:21
Habe nur das um die Buchstabenanzahl anzuzeigen:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var text : string;
    i, anzahl, Index, Ordnungszahl : integer;
    Buchstabe, key : char;
begin
 if not (key in [#65..#90, #97..#122, #8]) then
  key := #0;

 StringGrid1.Cells[0,0]:= 'Buchstabe';
 StringGrid1.Cells[1,0]:= 'Häufigkeit';
 StringGrid1.Cells[2,0]:= 'Prozent';

 for i := 0 to 26 do
 begin
   StringGrid1.Cells[0,i+1]:= char (i+65);
 end;
 text:= Edit1.Text;
 text:=stringreplace(text,' ','',[rfReplaceAll]);
 for n1 := 1 to length (text) do
    begin
    Buchstabe := text[n1];
    Buchstabe := Upcase (Buchstabe);
    Ordnungszahl:= Ord(Buchstabe);
    Index:= Ordnungszahl-64;
    if Index in [1..26] then
      begin
      anzahl := StrToIntDef(StringGrid1.Cells[1,Index],0);
      anzahl := anzahl + 1;
      StringGrid1.Cells[1,Index] := inttostr(anzahl);
      end;
    end;
   Edit2.Text:= inttostr(n1-1);
end;

Geändert von MrSpock (20. Feb 2017 um 07:43 Uhr) Grund: Delphi - Tags hinzugefügt.
  Mit Zitat antworten Zitat