Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionH := "O_OO__O___" n := 1; // début de la chaine // occurence 1 Mot(h,n,M,C,L); //-> n=2 M='O' C='O' L=1 Mot(h,n,M,C,L); //-> n=3 M='_' C='_' L=1 occurence 2 Mot(h,n,M,C,L); //-> n=5 M='OO' C='O' L=2 Mot(h,n,M,C,L); //-> n=7 M='__' C='_' L=2 occurence 3 Mot(h,n,M,C,L); //-> n=8 M='O' C='O' L=1 Mot(h,n,M,C,L); //-> n=11 M='___' C='_' L=3
procedure MOT(h:string; var N:integer; var M:string; var C:char; var L:integer); // h : chaine à analyser, on ne la touche pas // N : Début d'analyse dans la chaine, renvoie le début suivant // M : mot détecté // C : Caractère du mot détecté // L : Longueur du mot détecté begin if (n>length(h)) or (trim(h)='') then exit; // mettre éventuellement un message C := h[N]; // caractère de la position N dans la chaine h M :C; // mot premier carac L :1; // longueur 1 carac M := C; // premier carac inc(N); // caractère suivant while C=h[N] do begin inc(L); // 1 caractère de + inc(N); // position suivante M := M + C; // mot résultant end; end;
type TSeq = packed record PrSeq : string; Nombre : Integer; Alerte : Integer; PourChr : Integer; PChCar : string; end; function SearchSeq(Str: string): TSeq; var Posi : Integer; Value : string; CharPb : string; Pb0 : Integer; Pb_ : Integer; begin Pb0 := 0; Pb_ := 0; Posi := Pos('0', Str); ZeroMemory(@Result, SizeOf(Result)); Result.PrSeq := Copy(Str, 0, Posi); Value := Copy(Str, Posi + 1, Length(Str)); if Pos(Result.PrSeq, Value) = 1 then CharPb := Copy(Str, Length(Str) - Length(Value), Length(Value) + 1) else if Length(Result.PrSeq) = 1 then CharPb := Copy(Str, Pos(Result.PrSeq, Value), Length(Value) + 1) else CharPb := Value; while Pos(Result.PrSeq, Value) <> 0 do begin Posi := Pos(Result.PrSeq, Value); Inc(Result.Nombre); if CharPb[1] = '0' then Inc(Pb0) else Inc(Pb_); Value := Copy(Value, Posi + Length(Result.PrSeq), Length(Value)); if Pos(Result.PrSeq, Value) = 1 then CharPb := Copy(Str, Length(Str) - Length(Value), Length(Value) + 1) else if Length(Result.PrSeq) = 1 then CharPb := Copy(Str, Pos(Result.PrSeq, Value), Length(Value) + 1) else CharPb := Value; end; Result.Alerte := Pb0; if Pb0 = Pb_ then begin Result.PourChr := 50; Result.PChCar := '0 ou _'; end else begin if Pb0 > Pb_ then begin Result.PourChr := Round((100/(Pb0+Pb_))*Pb0); Result.PChCar := '0' end else begin Result.PourChr := Round((100/(Pb0+Pb_))*Pb_); Result.PChCar := '_'; end; end; end; procedure TForm1.Button1Click(Sender: TObject); var VSeq : TSeq; begin VSeq := SearchSeq(Edit1.Text); ShowMessage(Format( '- Nombre de Sequence : %d'+#13#10+ '- Nombre Alerte : %d'+#13#10+ '- Probabilité prochain caractère : %d /100'+#13#10+ '- Prochain caractère : %s', [VSeq.Nombre,VSeq.Alerte,VSeq.PourChr,VSeq.PChCar])); end;