Autor Beitrag
Robii
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 236



BeitragVerfasst: Di 02.06.09 22:07 
Hallo,

ich habe einen String, der mehrere tausend Zeichen umfasst. Bzw eine Datei in der mehrere tausend Zahlenketten vorhanden sind.
Und zwar nach dem Schema 'xZahlen'+' '+'xZahlen'. Ich möchte jetzt gerne in eine Procedure den String so aufteilen, das ich die erste
Zahlenkette nehme und mit ihr Arbeite, danach die zweite Zahlenkette usw. Wie ist das zu realisieren?

Grüße.
Tropby
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 71
Erhaltene Danke: 4

Vista, Win XP, Win 89
Turbo Delphi Ex.
BeitragVerfasst: Di 02.06.09 22:18 
Hi,

zuerst würde ich den File in eine TStringList laden.

Dann eine schleife bauen.

Ungefähr so:

ausblenden 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:
procedure Load ();
var 
  F : TStrings;
begin
  F := TStringList.Create();
  F.LoadFromFile('Filename');
  Zeichenketten(F.Text);
end;

procedure Zeichenketten (S : String);
var SW : String;
    ST : TStrings;
begin
  ST := TStringList.Create;
  while S <> '' do
  begin
    S := copy(S, pos(' ', S) + 1, Length(S));
    SW := copy(S, 1, pos(' ', S) - 1);
   
    // Hier jetzt SW Sortieren oder was auch immer 

    ST.Add(SW);
  end;
end;

Hab gerade nichts zum testen da aber so ungefähr sollte das Funktionieren.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 03.06.09 09:54 
oder wenn man faul ist:

F := TStringList.Create();
F.LoadFromFile('Filename');
F.Text := StringReplace(f,' ',#13#10);
...
...