AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Worthäufigkeit bestimmen

Ein Thema von Luckie · begonnen am 24. Feb 2004 · letzter Beitrag vom 4. Mär 2004
 
Benutzerbild von Pseudemys Nelsoni
Pseudemys Nelsoni

Registriert seit: 24. Dez 2002
Ort: Hamburg-Harburg
3.551 Beiträge
 
#4

Re: Worthäufigkeit bestimmen

  Alt 24. Feb 2004, 05:10
ne besser ist es keinesfalls, aber ich denke ich hätte es irgendwi hinbekommen.

also ich hatte es so(mit nem button und nem memo:

Delphi-Quellcode:
type
  TWordCount = Record
    word: string;
    count: integer;
  end;

...

procedure TForm1.Button1Click(Sender: TObject);
const
  FilePath: string = 'C:\Test.txt';
  sep: char = ' ';
var
  tf: TextFile;
  TempStr, TempWord: string;
  WordCount: Array of TWordCount;
  i: integer;
  IsInArray: boolean;
begin
  AssignFile(tf, FilePath);
  Reset(tf);
  while not EOF(tf) do
  begin
    ReadLn(tf, TempStr);
    TempStr := Trim(TempStr);
    TempStr := TempStr + ' ';
    while pos(sep, TempStr) > 0 do
    begin
      IsInArray := false;
      TempWord := Copy(TempStr, 1, Pos(sep, TempStr)-1);
      Delete(TempStr, 1, Pos(sep, TempStr));
      for i := low(WordCount) to high(WordCount) do
      begin
        if WordCount[i].word = TempWord then
        begin
          IsInArray := true;
          inc(WordCount[i].count);
        end;
      end;
      if not IsInArray then
      SetLength(WordCount, Length(WordCount)+1);
      WordCount[high(WordCount)].word := TempWord;
      WordCount[high(WordCount)].count := 1;
    end;
  end;
  for i := low(WordCount) to high(WordCount) do
    Memo1.Lines.Add('Wort "' + WordCount[i].word + '" ist ' + IntToStr(WordCount[i].count) + ' mal enthalten');
  CloseFile(tf);
  SetLength(WordCount, 0);
  WordCount := nil;
end;


ich glaube das array hab ich am ende falsch freigegeben oder?
Und noch ne Frage, beim ausführen des programms werden mir manche einträge doppelt angezeigt.

z.b wenn das die Textdatei ist:

Zitat:
hallo
hallo2 3
hi
hallo2
3
hi
hi
hi
hi
hi
hi
wird mir beim buttonclick des programms aber nur:

Zitat:
Wort "hallo" ist 1 mal enthalten
Wort "hallo2" ist 2 mal enthalten
Wort "3" ist 2 mal enthalten
Wort "3" ist 1 mal enthalten
Wort "hi" ist 1 mal enthalten
angezeigt. Kannst du mir sagen woran das liegt?
Mario
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz