怎么把右边列表里面的多余项,但是左边没有的项,删除掉???? 111       222
222       111
111       333
111       444
333       777左边列表框里面有111,222,333(重复的不管),右边除了111,222,333还有444,777,或者其他的左边没有的   怎么把这些左边没有的做个循环赛选掉

解决方案 »

  1.   

    strList1 := TstringList.Create;
    strList2 := TstringList.Create;
    try
      strList1.Text := '';
      strList2.Text := '';
      for i := strList2.count - 1 downto 0  do
      begin
        if strList1.IndexOf(strList2.Strings[i]) < 0 then
          strList2.Delete(i);
      end;
    finally
      strList1.Free;
      strList2.Free
    end;
      

  2.   

    应该是删除右边的 444 777吧?procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
    begin
        i:=0;
        while i< ListBox2.Items.Count do   //因为实时删除,ListBox2.Items.Count一直在变,所以不能用for
        begin
            if ListBox1.Items.IndexOf(ListBox2.Items.Strings[i])<0 then
            ListBox2.Items.Delete(i)
            else inc(i);
        end;
        ShowMessage('ok');
    end;