http://community.csdn.net/Expert/topic/3674/3674176.xml?temp=8.591861E-02type TIntSet = set of 1..250;var Set1, Set2: TIntSet;
 ...
Set1 := [1, 3, 5, 7, 9];
Set2 := [2, 4, 6, 8, 10]我的问题是
var s:string;s:='1,2,3,4,5,7,8's的值 如何赋给set1或赋给  if i in [值] then 急用,分不够另开贴 

解决方案 »

  1.   

    procedure TForm1.BitBtn5Click(Sender: TObject);
    type TIntSet = set of 1..250;
    var
      Set1, Set2: TIntSet;
      s: string;
      strings: TStrings;
      i: integer;
    begin
      s := '1,2,3,4,5,7,8';
      Set1 := [1, 3, 5, 7, 9];
      strings := TStringlist.Create;
      try
        ExtractStrings([','], [' '], PChar(s), strings);    for I := 0 to strings.Count - 1 do
        begin
          if not (strtoint(strings[I]) in set1) then
            include(set1, strtoint(strings[I]));
        end;
      finally
        strings.Free;
      end;
    end;
      

  2.   

    to: JonnySun(智者寡言)我要的结果为:  用s的值(字符类型string)取代set1的值来进行筛选.
        如 
           var i:integer;
           ...
           if i in [s的值] then 
           ...
      

  3.   

    我要的结果为:  用s的值(字符类型string)取代set1的值来进行筛选.
        如 
           var i:integer;
           s:string;
           begin
            s:='1,2,3,4,6,7';
            for i :=0 to 10 do
             if i in [s的值] then 
               ...
            end;
      

  4.   

    我的第一個回復是回復:s的值 如何赋给set1======================================================
        for I := 0 to strings.Count - 1 do
        begin
          if strtoint(strings[I]) in set1 then //如果存在
            Exclude(set1, strtoint(strings[I]));//刪除元素
          else
            Include(set1, strtoint(strings[I]));//加入元素
        end;
      

  5.   

    >>>>>或赋给  if i in [值] then 請描述清楚些!你到底要做什麼??if i in [值] then 是什麼東東? [值]是指什麼?
      

  6.   

    JonnySun(智者寡言)  非常感谢你
      
     如何把s的值(字符类型string)转换为set1 字符类型转换为TIntSet类.
      

  7.   

    下面的代碼是將  s := '1,2,3,4,5,7,8' 的值(字符类型string)转换为EmptySet
    轉換後EmptySet的值為EmptySet=[1,2,3,4,5,7,8]!!!
    明白沒有?? 基本上是這個思路.
    procedure TForm1.BitBtn7Click(Sender: TObject);
    type TIntSet = set of 1..250; //集合
    var
      EmptySet: TIntSet;
      S: string;
      Strings: TStrings;
      i: integer;
    begin
      s := '1,2,3,4,5,7,8';
      EmptySet := [];//高為空集合
      strings := TStringlist.Create;
      try
        ExtractStrings([','], [' '], PChar(s), strings);
        for I := 0 to strings.Count - 1 do
        begin
          if not (strtoint(strings[I]) in EmptySet) then
            include(EmptySet, strtoint(strings[I])); //±N©Ò¦³sªº­È¥[¤JEmptySet
        end;
      finally
        strings.Free;
      end;
    end;
      

  8.   

    ok 非常感谢JonnySun(智者寡言) !就是这个结果!下午另外开贴再送你100分.