假设我有
数据Tstrings
myTstrings:Tstrings;
现在共有14个数据
从0到13分别等于1,2,4,8.。
后一个数据就是前一个数据的乘2,
现在我有数据假设为3,我如何得到是
myTstrings.Strings[0]
和myTstrings.Strings[1]
的相加,或者我是数据如22得到
myTstrings.Strings[1]
myTstrings.Strings[2]
myTstrings.Strings[4]请问有什么好的方法,请高手指点
数据Tstrings
myTstrings:Tstrings;
现在共有14个数据
从0到13分别等于1,2,4,8.。
后一个数据就是前一个数据的乘2,
现在我有数据假设为3,我如何得到是
myTstrings.Strings[0]
和myTstrings.Strings[1]
的相加,或者我是数据如22得到
myTstrings.Strings[1]
myTstrings.Strings[2]
myTstrings.Strings[4]请问有什么好的方法,请高手指点
myTstrings.Strings[1]
myTstrings.Strings[2]
myTstrings.Strings[4]这个。
等有时间再来看吧。汗
var
Index: Integer;
begin
Result := '';
Index := 0;
while Value > 0 do
begin
if odd(Value) then Result := Result + AStrings[Index];
Value := Value shr 1;
inc(Index);
end;
end;
调用的例子:procedure TForm1.Button1Click(Sender: TObject);
var
MyStrings: TStrings;
begin
MyStrings := TStringList.Create;
try
MyStrings.Add('A');
MyStrings.Add('B');
MyStrings.Add('C');
MyStrings.Add('D');
MyStrings.Add('E');
MyStrings.Add('F');
MyStrings.Add('G');
MyStrings.Add('H');
MyStrings.Add('I');
MyStrings.Add('J');
ShowMessage (ValueToStrings(MyStrings, 22));
finally
MyStrings.Free;
end;
end;