Autor Beitrag
Ak-Alex
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 29.10.03 14:03 
Hallo,


ich habe einen Text mit mehreren Sätzen die durch ein <nz> getrennt sind.

Ich möchte jeden Satz in eine neue Zeile des MemoFeldes einfügen, dazu benutze ich folgenden Code, der aber wohl nicht richtig funzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
var
str , str1: string;
begin
str := idhttp1.get('http://www.domain.de/textt/text.txt');
while pos('<nz>',str) > 0 do
begin
str1 := copy(str,1,pos('<nz>',str) - 1);
Memo1.lines.Add(str1);
str := str1;
delete(str,1,pos('<nz>',str) - 1);
end;

end;


was ist falsch?


Die Textdatei sieht in etwa so aus:

ausblenden Quelltext
1:
satz1 <nz> satz2 <nz> satz3 <nz>					
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 29.10.03 14:18 
Der einfachere weg wäre die <nz>s durch #13#10 zu ersetzen und dann alles in die stringListe packen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject); 
var 
str: string; 
begin 
str := idhttp1.get('http://www.domain.de/textt/text.txt'); 
stringReplace(str,'<nz>',#13#10,[rfReplaceAll]);
Memo1.lines.Add(str); 
end;


:wink:

_________________
mfg.
mâximôv
focus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187

XP, 2k, 98, Me
D6 Prof
BeitragVerfasst: Mi 29.10.03 14:40 
Oder, wenn du auf das Parsen bestehst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var
  str, str2: string;
  idx, i: integer;
begin
  str := idhttp1.get('http://www.domain.de/textt/text.txt'); 
  idx:=0;
  while(length(str)>=idx)do
  begin
    str2:='';
    idx:=pos('<nz>', str);
    for i:=1 to idx-1do  str2:=str2+str[i];
    Memo2.Lines.Add(str2);
    delete(str,1,idx+length('<nz>')-1);
  end;
end;

Gruss
Michael
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 29.10.03 15:18 
Warum wollt ihr alle eigentlich immer destruktiv parsen? ...wenn man posEx() benutzt dann kann man sich das delete sparen und vermutlich viel zeit :wink:

_________________
mfg.
mâximôv
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 29.10.03 15:29 
Hallo,

@maximus

D5 kennt kein posEx.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 29.10.03 15:38 

_________________
mfg.
mâximôv
Ist die Frage beantwortet? Das Problem gelöst?

Dann klicke hier, um das Thema entsprechend zu markieren!