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 急用,分不够另开贴
...
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 急用,分不够另开贴
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;
如
var i:integer;
...
if i in [s的值] then
...
如
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;
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;
如何把s的值(字符类型string)转换为set1 字符类型转换为TIntSet类.
轉換後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;