Autor Beitrag
huhn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: Do 06.10.05 22:26 
Hi leute!
ich bin über ein seltsammes problem gestoßen, und das sieht wie folgt aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm.Button1Click(Sender: TObject);
var s:string;  von, bis:integer;
begin
s:='tr lsdfsg trz tr asdfgadg trz tr sdf trz tr sdfsdf trz';
repeat
  von:=pos('tr',s)+2;
  bis:=pos('trz',s);
  Memo1.Lines.add(copy(s,von,bis-von));
  s:=copy(s,bis+3,length(s)-bis-3);
until pos('trz',s)=0;
end;

in meiner schleife sollten praktisch alle strings zwischen "tr" und "trz" ausgegeben werden, jedoch fehlt immer die letzte angabe, also "sdfsdf".
ergänze ich den string mit irgendeinen scheiß das mindestens 2 buchstaben hat funktioniert es wieder.
s:='tr lsdfsg trz tr asdfgadg trz tr sdf trz tr sdfsdf trz sd';
kann mir einer sagen warum???
oder hab ich so ein brett vorm kopf das ich den fehler net sehe?
mfg huhn


Moderiert von user profile iconKlabautermann: Topic aus Sonstiges verschoben am Do 06.10.2005 um 23:15

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 06.10.05 22:54 
Hallo,

lass Dir mal z.B. mit showmessage bei jedem Durchlauf die variable 'S' anzeigen,
dann siehst Du deinen Fehler. :wink:

Du schneidest jedesmal ein Zeichen am Ende ab.
Hängst Du irgendwas an,
dann hast Du genug Zeichen am Ende zum Abschneiden,
und man vermutet das es richtig läuft.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
infofreak
Hält's aus hier
Beiträge: 7

WinXP Prof., Suse Linux 9.3 Personal
D2005 Personal
BeitragVerfasst: Do 06.10.05 23:03 
ausblenden Delphi-Quelltext
1:
s:=copy(s,bis+3,length(s)-bis-3);					


Hier steckt der Bösewicht.
Daraus muss
ausblenden Quelltext
1:
s:=copy(s,bis+3,length(s)-bis-2);					

werden.

Gruß Thomas
huhn Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 272
Erhaltene Danke: 1

WIN XP
D7Pers
BeitragVerfasst: Do 06.10.05 23:07 
da schau an!!! tatsächlich!
er schneidet jedesmal 1 zeichen ab, abgeändert funktioniert es.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var s:string;  von, bis:integer;
begin
s:='tr lsdfsg trz tr asdfgadg trz tr sdf trz tr sdfsdf trz';
repeat
  von:=pos('tr',s)+2;
  bis:=pos('trz',s);
  Memo1.Lines.add(copy(s,von,bis-von));
  s:=copy(s,bis+3,length(s)-(bis+2)); 
  Memo1.Lines.add(s);
until pos('trz',s)=0;
end;

ahhhhh und jetzt seh ichs au!die pos gib immer die stelle zwischen den buchstaben an und dann muss ich natürlich 1 dazuzählen
thx lannes & infobreak, einfach en brett vorm gesicht gehabt
mfg huhn

_________________
Quod Erat Demonstrandum-Was zu beweisen war! *THX to Chrissivo!*