怎样将字符串转换为字节类型?(50分)

  • 主题发起人 hangyang
  • 开始时间
H

hangyang

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位怎样实现下面的功能啊
ss:='1234567890ABB9'怎样将他们变为字节类型啊
即变为
MyArray[0]:=$12;
MyArray[1]:=$34;
MyArray[2]:=$56;
MyArray[3]:=$78;
MyArray[4]:=$90;
MyArray[5]:=$AB;
MyArray[6]:=$B9;
怎样实现这样的算法啊 谢谢!
 
本来就是
不用转换
 
var
ss:string;
i,l:integer;
MyArray:array of Byte;
begin
ss:='1234567890ABB9';
i:=1;
l:=Length(ss);
SetLength(MyArray,l div 2);
While i<ldo
begin
if ss in ['0'..'9'] then
MyArray[i div 2 ]:=(ord(ss)-$30)*16
else
MyArray[i div 2 ]:=(ord(ss)-$37)*16;
if ss[i+1] in ['0'..'9'] then
MyArray[i div 2 ]:=MyArray[i div 2 ]+ord(ss[i+1])-$30
else
MyArray[i div 2 ]:=MyArray[i div 2 ]+ord(ss[i+1])-$37;
i:=i+2
end
end;
 
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ss: string;
i, l: integer;
MyArray: array of Byte;
begin

ss := '1234567890ABB9';
l := Length(ss);
SetLength(MyArray, l div 2);
for i := 0 to high(MyArray)do
begin
MyArray := StrToInt('$' + copy(ss, i * 2 + 1, 2));
end;
////////////////
SetLength(MyArray, 0);
end;
 
感谢关注 问题已经解决!
 

Similar threads

S
回复
0
查看
950
SUNSTONE的Delphi笔记
S
S
回复
0
查看
771
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
654
import
I
顶部