Autor Beitrag
icedre
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Sa 26.02.05 16:54 
Hallo,

gibt es eine Möglichkeit, einen String auf die Häufigkeit eines Buchstaben zu überprüfen (?)...
Also so etwas wie haeufigkeit:=function_für_häufigkeit('A', wort) :?:

Vielen Dank, icedre !

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
jaenschi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Sa 26.02.05 16:58 
Mahc doch eine Schleife:
ausblenden Delphi-Quelltext
1:
2:
z:=0;
while pos(suchstring,string)<>0 do inc(z);

z ist dann die Anzahl von suchstring in String
OneOfTen
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 26.02.05 17:01 
jaenschi hat folgendes geschrieben:
Mahc doch eine Schleife:
ausblenden Delphi-Quelltext
1:
2:
z:=0;
while pos(suchstring,string)<>0 do inc(z);

z ist dann die Anzahl von suchstring in String


wenn der Buchstabe gefunden wird, wäre das eine Endlosschleife..

//edit
komische Zitatfunktion, macht aus "<>" "&lt;&gt;"
jaenschi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Sa 26.02.05 17:04 
dann eben
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
z:=0;
while pos(suchstring,string)<>0 do 
begin 
 inc(z);
 delete(string,1,pos(suchstring,string));
end;


//edit
Der String ist danach allerdings um einiges kürzer;) also vorher sichern!
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Sa 26.02.05 17:09 
Hallo,

danke; Aber wenn ich es mit der Schleife mache, wird der String "verändert"; der String soll nicht verändert werden, gibt es nicht eine einfache function dafür???

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
jaenschi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

Win XP, Debian
D7
BeitragVerfasst: Sa 26.02.05 17:12 
Eine fertige Function gibt es nicht. Du kannst ja eine Variable temp als String deklarieren und ihr dann den String übergeben und temp in der Schleife benutzen!
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Sa 26.02.05 17:16 
o.k.

Ich merk gerade, dann ich mich ziemlich blöd anstell...
Erstmal vielen Dank, werd es jetzt einfach versuchen.
Bis dann !

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 26.02.05 17:22 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Var
 Haeufigkeit : array[#0..#255] of Integer;
 I : Integer;
 S : String;
begin
 S := 'Delphi-Forum.de Foren-Übersicht » VCL (Visual Component Library) » Häufigkeit eines Buchstaben in einem String ???';
 FillChar(Haeufigkeit, SizeOf(Haeufigkeit), 0);
 For I := 1 to length(S) do
  inc(Haeufigkeit[UpCase(S[I])]); // falls es Case-Sensitive sein soll, dann ohne UpCase
 ShowMessage('A kommt '+inttostr(Haeufigkeit['A'])+' mal vor');
end;


//Edit: Falls du wirklich nur herausfinden willst, wie oft EIN EINZIGER Buchstabe vorkommt, dann benütz Sprints Methode.


Zuletzt bearbeitet von delfiphan am Sa 26.02.05 17:36, insgesamt 1-mal bearbeitet
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 26.02.05 17:31 
icedre hat folgendes geschrieben:
gibt es eine Möglichkeit, einen String auf die Häufigkeit eines Buchstaben zu überprüfen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function MyFunction(const AString: String; AChar: Char): Integer;
var
  I: Integer;
begin

  Result := 0;
  for I := 1 to Length(AString) do
    if AString[I] = AChar then
      Inc(Result);

end;

_________________
Ciao, Sprint.