假设
数组1 数组2
2      3
3      5
4我要通过比较后取出2,4放到某一数组3
5放到另一个数组4在php中很容易实现,有个函数array_diff
delphi中数组或stringlist中是否有类似函数?
用循环比较取值的话,我已会。

解决方案 »

  1.   

    TStrings, TStringList类中都没有类似的函数。还是自己写个函数来实现吧,不复杂。
      

  2.   

    集合运算符: 
    +  -  *  <=  >=  =  <>  in
    +(并集)
    -(差集)
    *(交集)
    <=(子集)
    >=(超集)
    这种情况,是要声明类型为集合吗?
    这样应该能实现吧
      

  3.   

    PHP这么强大,比较数组函数都提供?
    不过原型一样的,写一个也很简单,如果想优化点的参照PHP原始函数写。
      

  4.   


    --------------------------------
    集合小没问题,太多元素不行。----------------------------------
      type
      TIntSet = set of byte ;
      const
      A : TIntSet = [2,3,4];
      B : TIntSet = [3,5];
      procedure DisplayResult( ASet : TIntSet );
    var
      Form1: TForm1;
    implementation{$R *.dfm}
    procedure DisplayResult( ASet : TIntSet );
    var
    I : Byte;
    begin
    for I := Low(Byte) to High(Byte) do
    if( I In ASet ) then
    Form1.Memo1.Lines.Add( IntToStr(I));
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    varC :TIntSet ;
    begin
     C:=[];
     C:=A-B;
     DisplayResult(C);
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    var
    C :TIntSet ;
    begin
     C:=[];
     C:=B-A;
     DisplayResult(C);
    end;