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



BeitragVerfasst: So 14.11.04 13:37 
Also folgendes:

Ich bin ein absoluter Anfänger in Delphi.
Das einzige was ich bis jetzt programmiert habe ist, die Zeichen eines Wortes in einem Label anzuzeigen.
Deswegen hier meine Frage:

Wie kann ich z.B. die 'e's in einem Wort zählen und dann ausgeben lassen?

Danke im voraus
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 14.11.04 13:48 
du gehst den string Buchstabe für Buchstabe inner schleife durch und erhöhst bei jedem "e" ne integer variabledie du am schluss auswerten kannst

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Feneriumpower Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 14.11.04 13:56 
Ja richtig ist das schon, aber genau das ist ja meine Problem, ich weiß nicht wie ich die 'e's in den String zählen soll. ich habe mir das so vorgestellt:


for zählvariable:=1 to length(Edit1.Text) do

und was kommt jetzt hier aber rein?


Label1.Caption:=IntToStr(anzahl);
heinze
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 112

XP
D4 Prof
BeitragVerfasst: So 14.11.04 14:18 
da gibt es mindestens 2 möglichkeiten

soviel wie ich hier gelernt hab ist ein string ein array von char
wen man also schreibt
ausblenden Quelltext
1:
2:
3:
4:
a,b:string;

i:='hallo';
b:=i[1];


dann müste b entwerder 'h' oder 'a' jenachedem ob es bei null anfängt must halt testen

wen das nicht geht suchmal nach copy in der hilfe

_________________
Für Fehler haftet die Tastatur bzw Für Gramatik ist meine legasthenie zu verklagen sonstige Verbesserungsvorschläge meiner Text bitte per pn an mich
Feneriumpower Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 14.11.04 14:24 
Das müsste doch auch mit einer IF-Anweisung funktionieren, oder?
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 14.11.04 14:26 
ja (if string[i] = 'e' then ...)

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Feneriumpower Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 14.11.04 14:27 
übrigens heinze, du hast es für ein bestimmtes Wort gemacht, aber ich möchte es für beliebige wörter machen, die man in ein Edit-feld schreiben kann
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 14.11.04 15:04 
und?
ich denke das er das weiß war ja auch nur ein beispiel

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: So 14.11.04 15:37 
also....ja, ein String ist ein Array vom Typ Char....es fäng aber bei 1 an...so ist zb wenn der String a:='Hallo'; lautet, ist a[1]=H, a[2]=a usw.....
dann gehst du eben in einer For-Schleife alle Buchstaben durch, also von i bis length(text), wobei du text vorher aus nem edit feld eingelesen hsat mit text:=edit1.text;meinetwegen.
dann guckst du, ob text[i]='e'; und wenn das erfüllt ist, erhöst du einen Zähle, den du vorher auf 0 initialisiert hast um eins!
Das ist das das Prinzip, das du verfolgen musst.