Exclure des caracteres d'une chaine.


Contenu du snippet

Function ExcludeChars(Const S : String; const CS : TSysCharSet): String;
Var P, PR : PByte;
    Size, I    : Integer;
Begin
  P    := PByte(S);
  Size := Length(S);
  SetLength(Result, Size);
  PR   := PByte(Result);
  I := 0;
  While P^ <> $0 do Begin
    If Not (Chr(P^) in CS) Then Begin 
      Pr^ := P^;
      Inc(Pr);
    End
    Else Inc(I);
    Inc(P);
  End;
  If I > 0 Then SetLength(Result, Size - I)
End;

Function ExcludeChars(Const S : String; const CS : TSysCharSet): String;
Var P, PR : PByte;
    BS : Set Of Byte Absolute CS;
    Size, I    : Integer;
Begin
  P    := PByte(S);
  Size := Length(S);
  SetLength(Result, Size);
  PR   := PByte(Result);
  I := 0;
  While P^ <> $0 do Begin
    If Not (P^ in BS) Then Begin 
      Pr^ := P^;
      Inc(Pr);
    End
    Else Inc(I);
    Inc(P);
  End;
  If I > 0 Then SetLength(Result, Size - I)
End;



Compatibilité : Delphi 5

Disponible dans d'autres langages :

A voir également