Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
Delphi 10.4 Sydney
|
AW: String buchstabenweise in array einlesen
13. Jun 2011, 01:02
Vermutlich meint dein Lehrer lediglich das:
Delphi-Quellcode:
type
TCharArray = array of Char;
function LowerCaseChar (const C: char): char;
begin
Result:= C;
if (Result in ['A'..'Z', 'Ä', 'Ö', 'Ü']) then
Inc(Byte(Result), 32);
end;
function FindChar (const S: TCharArray; const C: char): integer;
var
I: integer;
begin
Result:= 0;
for I:= 0 to Length(S)-1 do
if S[I] = C then Inc(Result);
end;
procedure TForm1.Edit2Change(Sender: TObject);
var
I, L1, L2, N: integer;
C: char;
S: TCharArray;
begin
Label1.Caption:= '';
L1:= Length(Edit1.Text);
L2:= Length(Edit2.Text);
if ((L1 > 0) and (L2 > 0)) then
begin
SetLength(S, L1);
for I:= 1 to L1 do
S[I-1]:= LowerCaseChar(Edit1.Text[I]);
C:= LowerCaseChar(Edit2.Text[1]);
N:= FindChar(S, C);
Label1.Caption:= 'Buchstabe ' + C + ' kommt ' + IntToStr(N)+' mal vor.';
SetLength(S, 0);
end;
end;
|
|
Zitat
|