Ich habe mal eine ähnlich Frage gehabt und diesen Code als Antowrt bekommen:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
| procedure TMDIChild.CalcWords; var Anzahl, i : integer; s1 : String; RTF : TStringList; begin RTF := TStringList.Create; try RTF.Text := Editor.Text; Anzahl := 0; for i := 0 to RTF.Count-1 do begin s1 := RTF[i]; if length(s1) > 0 then begin if s1[length(s1)] <> '-' then begin RTF[i] := RTF[i]+' '; end; end; end; s1 := RTF.Text; while Pos(' ',s1) > 0 do begin Inc(Anzahl); Delete(s1,1,Pos(' ',s1)); s1 := TrimLeft(s1); end; ShowMessage(Format('Es wurden %d Wörter gezählt', [Anzahl])) finally RTF.Free end end; |
Ich hoffe es hilft
Moderiert von
Tino: Code- durch Delphi-Tags ersetzt.