Informatik Material Portal Portfolio Präsentation Grafik Tabellenkalkulation Informatik56 9 10 11 12 13 Messen, Steuern, Regeln Linux Theorie Didaktik Open Source Spiele Wettbewerbe Netzbetreuung intern Literatur Links Energie corewar UNIX/Linux
Pfad: Startseite / Fächer / Informatik
Autor: be
21.09.2005 10:43
524

Buchstabe e zählen - Lösung

unit mBuchstabeEZaehlen;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    edText: TEdit;
    Label1: TLabel;
    lbAnzahl: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
    function zaehlen: Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function TForm1.zaehlen: Integer;
var i, anzahl: Integer;
begin
  anzahl := 0;
  for i:=1 to Length(edText.Text) do
    if edText.Text[i] = 'e' then
      Inc(anzahl);
  zaehlen := anzahl;
end;

procedure TForm1.Button1Click(Sender: TObject);
var anzahl: Integer;
begin
  anzahl := zaehlen;
  lbAnzahl.Caption := 'Anzahl der e''s: ' + IntToSTr(anzahl);
end;

end.