AGB  ·  Datenschutz  ·  Impressum  







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

Frage zu einer funktion

Ein Thema von Pseudemys Nelsoni · begonnen am 4. Dez 2003 · letzter Beitrag vom 4. Dez 2003
Antwort Antwort
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: Unterhaching
11.421 Beiträge
 
Delphi 12 Athens
 
#1

Re: Frage zu einer funktion

  Alt 4. Dez 2003, 14:49
Hier meine Lösung:

Delphi-Quellcode:
procedure CountWords(Txt: AnsiString; var Words, Spaces, SentenceChars,
    OtherChars: Integer);
var
  InLegalWord: Boolean;
  I: Integer;
const
  SENTENCE_SET = '.,;!?';
begin
  Words := 0;
  Spaces := 0;
  SentenceChars := 0;
  InLegalWord := False;
  for I := 1 to Length(Txt) do
  begin
    if Txt[I] in ['A'..'Z', 'a'..'z'] then
    begin
      InLegalWord := True;
    end else begin
      if InLegalWord then
      begin
        Inc(Words);
        InLegalWord := False;
      end;
      if Txt[I] in [#0..#32] then
        Inc(Spaces)
      else if Pos(Txt[I], SENTENCE_SET) > 0 then
        Inc(SentenceChars)
      else
        Inc(OtherChars);
    end;
  end;
end;
Der Aufruf erfolgt wie folgend:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  Words, Spaces, SentenceChars, OtherChars: Integer;
begin
  CountWords(Memo1.Text, Words, Spaces, SentenceChars, OtherChars);
  Label1.Caption := IntToStr(Words);
  Label2.Caption := IntToStr(Spaces);
  Label3.Caption := IntToStr(SentenceChars);
  Label4.Caption := IntToStr(OtherChars);
end;
......
Lizbeth W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Antwort Antwort


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 23:17 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