var Src : TStringList; Pdp : TStringList; Tot : TStringList; I : Integer; Val : array of Integer; begin Src := TStringList.Create; Pdp := TStringList.Create; Tot := TStringList.Create; ZeroMemory(Val, 0); SetLength(Val, 2); try Tot.Delimiter := ' '; Src.LoadFromFile('d:\fichier.txt'); for I := 0 to Src.Count - 1 do begin if Pos('PDP',Src[I]) <> 0 then begin Pdp.Add(Src[I]); Pdp.Add(Src[I+1]); Tot.DelimitedText := Src[I+1]; if Tot[Tot.Count-2] = '0' then Val[0] := Val[0] + StrToIntDef(Tot[Tot.Count-2],0)+1; Pdp.Add(Src[I+2]); Tot.DelimitedText := Src[I+2]; if Tot[Tot.Count-2] = '3' then Val[1] := Val[1] + StrToIntDef(Tot[Tot.Count-2],0)+3; end; end; Pdp.Add(Format('Nombre Total PDP0 : %d',[Val[0]])); Pdp.Add(Format('Nombre Total PDP3 : %d',[Val[1]])); Pdp.SaveToFile(ExtractFilePath(Application.ExeName)+'PDP.txt'); ShowMessage(Format('Nombre Total PDP0 : %d'#13#10'Nombre Total PDP3 : %d',[Val[0],Val[1]])); finally Src.Free; Pdp.Free; Tot.Free; end;@+
if Tot[Tot.Count-2] = '3' then Val[1] := Val[1] + StrToIntDef(Tot[Tot.Count-2],0)+3;Ici supprime le +3 ou StrToIntDef(Tot[Tot.Count-2],0) sinon on fait 3+3.
ZeroMemory(Val, 0); SetLength(Val, 2);Je vide mon tableau Val et je redimensionne en dynamique à 2 mon Val = array[0..1]of integer
Tot[Tot.Count-2]Ceci pour partir de la fin du tableau car la deuxième ligne est peut-être vide ou un chr...
PROC PDP R0P
A 0 OK
3 OK
PROC PDP R0P
B 0 OK
3 OK
PROC PDP R0P
C 0 OK
3 OK
PROC PDP R0P
A 0 OK
PROC PDP R0P
C 0 OK
3 OK
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
PROC PDP R0P
0 OK
Pdp.Add(Src[I]);
Pdp.Add(Src[I+1]);
Tot.DelimitedText := Src[I+1];
showmessage(Tot.Text);
if Tot[1] = '0' then
Val[0] := Val[0] + StrToIntDef(Tot[1],0)+1;
Pdp.Add(Src[I+2]);
Tot.DelimitedText := Src[I+2];
showmessage(Tot.Text);
if Tot[0] = '3' then
Val[1] := Val[1] + StrToIntDef(Tot[0],0);
PROC PDP R0P
0 OK
var Src : TStringList; Pdp : TStringList; Tot : TStringList; I : Integer; Val : array of Integer; begin Src := TStringList.Create; Pdp := TStringList.Create; Tot := TStringList.Create; ZeroMemory(Val, 0); SetLength(Val, 2); try Tot.Delimiter := ' '; Src.LoadFromFile('d:\fichier.txt'); for I := 0 to Src.Count - 1 do begin if Pos('PDP',Src[I]) <> 0 then begin Pdp.Add(Src[I]); Pdp.Add(Src[I+1]); Tot.DelimitedText := Src[I+1]; if Tot.Count <> 0 then //Si le tableau n'est pas vide if Tot[Tot.Count-2] = '0' then Val[0] := Val[0] +1; Pdp.Add(Src[I+2]); Tot.DelimitedText := Src[I+2]; if Tot.Count <> 0 then //Si le tableau n'est pas vide if Tot[Tot.Count-2] = '3' then Val[1] := Val[1] +3; end; end; Pdp.Add(Format('Nombre Total PDP0 : %d',[Val[0]])); Pdp.Add(Format('Nombre Total PDP3 : %d',[Val[1]])); Pdp.SaveToFile(ExtractFilePath(Application.ExeName)+'PDP.txt'); ShowMessage(Format('Nombre Total PDP0 : %d'#13#10'Nombre Total PDP3 : %d',[Val[0],Val[1]])); finally Src.Free; Pdp.Free; Tot.Free; end;@+