Autor Beitrag
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: So 09.01.05 19:06 
Hi!!!

Folgendes Problem: Ich hab' nen String wie z.B. den da:
Ganz toller String:
Ich finde das delphi-forum super!!

Jetzt will ich, dass dieser String in die einzelnen wörter eingeteilt wird. Also in unserem Beispiel:

wort[1] = Ich
wort[2] = finde
wort[3] = das
wort[4] = delphi-forum
wort[5] = super!!

Danke schon mal, gelle?? :D

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
Handycommander
ontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1054

Windows XP Pro, Vista
Visual Studio 2008
BeitragVerfasst: So 09.01.05 19:10 
Hallo,

ich hoffe mal, das hier kann dir helfen! :roll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure GetWords(TheString, Separator: Stringvar Strings: TStringList);
begin
  try
    Strings.Clear;
    while Pos(Separator, TheString)>0 do
    begin
      Strings.Add(Copy(TheString, 1, Pos(Separator, TheString)-1));
      TheString:=Copy(TheString, Pos(Separator, TheString)+Length(Separator),
      Length(TheString));
    end;
    Strings.Add(TheString);
  except
  end;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function WordCount(TheString, Separator: String): Integer;
var OurStrings: TStringList;
begin
  OurStrings:=TStringList.Create;
  GetWords(TheString, Separator, OurStrings);
  result:=OurStrings.count;
  OurStrings.free;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function GetWord(TheString, Separator: String; Nummer: Integer): String;
var OurStrings: TStringList;
begin
  OurStrings:=TStringList.Create;
  GetWords(TheString, Separator, OurStrings);
  try
    result:=OurStrings[Nummer-1];
  except
    result:=''
  end;
  OurStrings.free;
end;



MfG

Tobias

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 09.01.05 19:12 

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 09.01.05 19:22 
WeBsPaCe hat folgendes geschrieben:
Jetzt will ich, dass dieser String in die einzelnen wörter eingeteilt wird.

ausblenden Delphi-Quelltext
1:
uses Types;					

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
function Explode(const AText: String; ADelimiter: Char): TStringDynArray;
var
  I: Integer;
begin

  with TStringList.Create do
    try
      Delimiter := ADelimiter;
      DelimitedText := AText;
      if Count > 0 then
      begin
        SetLength(Result, Count);
        for I := 0 to Count - 1 do
          Result[I] := Strings[I];
      end;
    finally
      Free;
    end;

end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject);
var
  StrArry: TStringDynArray;
  I: Integer;
begin

   StrArry := Explode('Ich finde das delphi-forum super!!'#32);
   if Length(StrArry) > 0 then
     for I := 0 to High(StrArry) do
       ShowMessage(StrArry[I]);

end;

_________________
Ciao, Sprint.
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 09.01.05 19:25 
Will noch einer? :mrgreen:

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mo 10.01.05 16:02 
Hey Jungs, ihr seid super!!! Vielen Dank!!! Alle drei funzen!!! Ich such mir dann mal eins raus... :D :lol:

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
zangelo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 50



BeitragVerfasst: Mo 10.01.05 21:44 
Hi, bin ein delphi anfänger, und mich interessiert nun, wo das jetzt hin muss, also der code, einfach doppelklick auf die form, und dann die 3 codes einfügen?