Autor Beitrag
bluecat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mi 22.06.05 11:10 
Hallo Leute!
ich möchte verschiendenen Buchstaben in einem String zählen und danach zurückgeben, weiss aber nicht wie ich machen kann.Wie lautet der Code? Kann jemand mir helfen? Danke!
Bsp: "wetrwetw"
rückgabe: w:=3 ,t:=2, r:=1
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mi 22.06.05 11:43 
Die Rückgabe is ein Array [Char] Of Integer. Dort steht für jedes Zeichen, wie oft es in dem String vorgekommen ist.
Hier ist der Prozedurkopf:
ausblenden Delphi-Quelltext
1:
2:
Type TCharOfInt = Array [Char] Of Integer;
Procedure CountCharacters (Const aString : StringVar aResults : TCharOfInt);

Den Rest schaffst Du doch, oder?
bluecat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mi 22.06.05 11:56 
ich kann leider nicht vorstellen?bin vielleich zu blöd,kannst du mir bitte den code posten! danke
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 22.06.05 12:10 
Ergebnis, wenn man im Forum nach Buchstaben sucht.
Ich vermute, dass das dein Problem löst.
bluecat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mi 22.06.05 12:20 
danke für den hinweis, ich möchte aber Einzelbuchstaben zählen.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 22.06.05 12:27 
Ich weiß ja nicht, wieviel Programmiererfahrung du hast, aber wenn du meinen Beispiel-Source nimmst (im oben verlinkten Topic), sollte es mit ein paar kleinen Abwandlungen recht schnell funktionieren.

Statt der Buchstabengruppen nimmst du ein Array der Länge 40 (Alle Buchstaben und Zahlen, wenn ich mich nicht verzählt habe) vom Typ Integer.
Dann kannst du über eine Case-Struktur jedes Zeichen prüfen und eintragen. Das ist die Anfänger-Variante.
Die Profi-Variante kann man über den ASCII-Wert des Buchstaben noch einiges verbessern.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 22.06.05 12:31 
Das Denken kann Die dieses Forum leider nicht abnehmen ...

Type-Deklaration von user profile iconalzaimar nehmen und
ausblenden Delphi-Quelltext
1:
2:
For X:= 1 To Length(Input) Do
    Inc(Result[Input[X]]);
nehmen ...

Geht übrigens auch als Function:
ausblenden Delphi-Quelltext
1:
function CountCharacters (Const Input : String): TCharOfInt;					

Wird aber intern genauo gehandlet wie user profile iconalzaimars Aufruf.
That's it ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.