Autor Beitrag
GGfan
Hält's aus hier
Beiträge: 7

Win ME, SuSe Linux 8.0, Win 95
Delphi 7
BeitragVerfasst: Di 25.01.05 13:02 
Ich möchte ein Programm schreiben, bei dem man einen Satz eingibt, und das Programm die Wörter in die Elemnte einer Array yumwandelt so das "Heute ist ein schöner Tag" so cverarbeitet wird:
arrayname[0] = Heute
arrayname[1] = ist
arrayname[2] = ein
usw...

gibts da einen einfachen Bewehl.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 25.01.05 13:29 
Es geht vermutlich auch kürzer !!

ausblenden volle Höhe Delphi-Quelltext
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:
36:
37:
38:
function SubStr(text,stop : String; var nextpos : integer):string;
var i,j   :integer;
begin
  i:= 1;
  j:= 0;
  while (j<i) do j:= j + pos(stop, copy(text,j+1,1024));
  j:= j-i;
  nextpos := j+1;
  result := copy(text,i,j);
end;



procedure TForm1.BitBtn1Click(Sender: TObject);
var tempStr,s : String;
    i : integer;
    exit : boolean;
    next : Integer;
    arrayname : array[0..4] of String;
begin
   tempStr := 'Heute ist ein schöner Tag';
   exit := False;
   i := 0;
   while not exit do
   begin
     if pos(' ',tempstr) <> 0 then
     begin
       s := substr(tempStr,' ',next);
       delete(tempstr,1,next);
     end else
     begin
       s := tempStr;
       exit := True;
     end;
     arrayname[i] := s;
     inc(i);
   end;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.


Zuletzt bearbeitet von chrisw am Di 25.01.05 13:30, insgesamt 2-mal bearbeitet
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 25.01.05 13:29 
Hallo!

Halte mal in der FAQ-Sparte nach "Explode" Ausschau.

Cu,
Udontknow
GGfan Threadstarter
Hält's aus hier
Beiträge: 7

Win ME, SuSe Linux 8.0, Win 95
Delphi 7
BeitragVerfasst: Di 25.01.05 16:40 
Danke für die Hilfe, aber ich glaub das wäre noch ein bisschen zu schwer für mich.
Ich hab das jetzt so gelöst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
var teil1: string;
    n , nold: integer;
    arr: array[0..6] of string;
begin
  anweisung := 'Delphi ist ja der absolute wahnsinn';
  nold := 0;
  for n := 0 to length(anweisung) + 1 do
  begin
    if (anweisung[n] = ' ') or (n = length(anweisung) + 1) Then
    Begin
      teil1 := copy(anweisung, nold, n - nold);
      nold := n;
      form1.Caption := form1.caption + teil1;
    End;
  end;
end;