Autor Beitrag
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Mo 27.03.06 19:53 
Hallo,

ich habe Funktion geschrieben, die einen String in verschiedene Argumente unterteilt, diese ignoriert aber aus irgendeinem Grund immer das letzte Argument...

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:
function ArgDiv(const msg: String) : Boolean;
var a,b,i: Integer;
    numArgs: Integer;
    Argument: Array[0..2] of String;
begin
  a:=1; b:=a; numArgs:=0;
  if msg<>'' then
    while msg[a]<>'' do
    begin
      if msg[a]='#' then 
      begin
        Argument[numArgs]:=''; 
        for i:=b to (a-1) do
          Argument[numArgs]:=Argument[numArgs]+msg[i];
        inc(numArgs); b:=a+1;
      end;
      inc(a);
    end;

  [...]

end;


Ich gebe als String 'LOGIN#User#Pass' an, heraus kommt allerdings als
->Argument[0]='LOGIN'
->Argument[1]='User'
->Argument[2]=''

Kann mir da jemand helfen? Schonmal vielen Dank!


Moderiert von user profile iconUGrohne: Topic aus Sonstiges (Delphi) verschoben am Mo 27.03.2006 um 20:56
Spatz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

WIN 2k
D7E
BeitragVerfasst: Mo 27.03.06 20:07 
nun, du durchläufst den String und immer wenn du ein # findest, dann speicherst du alles vor dem Zeichen im Array ab.
also:
LOGIN#User#Pass => LOGIN
User#Pass => User
Pass -> und nun wird kein # mehr gefunden und der String wird auch nicht mehr abgespeichert.

Würdest du LOGIN#User#Pass# nehmen, so würde es funktionieren.

Gruss

_________________
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
fidionael Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Mo 27.03.06 20:58 
Ah vielen Dank :)

Ich wusste, dass es ein dummer Fehler sein würde, aber ich habe ihn nach zwei Stunden Suche nicht gefunden... Jetzt funktioniert es jedenfalls. Nochmals vielen Dank