是0-255,转换可以直接赋值给string,比如:var c:Char; s:string; begin c:=#177; s:=c; s:=c+#153; ShowMessage(s); end;
那byte和char两种变量类型,好像没有什么区别了?
var b:byte; c:char; b:=$31; c:=char(b);//'1' 或是:c:=chr(b);c:='2'; b:=ord(c);//$32 0x32H
请问那个ord函数是什么意思?Delphi Help中的例子如下:uses Dialogs; type Colors = (RED,BLUE,GREEN);var S: string; begin S := 'BLUE has an ordinal value of ' + IntToStr(Ord(BLUE)) + #13#10; S := S + 'The ASCII code for "c" is ' + IntToStr(Ord('c')) + ' decimal'; MessageDlg(S, mtInformation, [mbOk], 0, mbOK); end;
c:Char;
s:string;
begin
c:=#177;
s:=c;
s:=c+#153;
ShowMessage(s);
end;
b:byte;
c:char;
b:=$31;
c:=char(b);//'1' 或是:c:=chr(b);c:='2';
b:=ord(c);//$32 0x32H
type Colors = (RED,BLUE,GREEN);var S: string;
begin
S := 'BLUE has an ordinal value of ' + IntToStr(Ord(BLUE)) + #13#10;
S := S + 'The ASCII code for "c" is ' + IntToStr(Ord('c')) + ' decimal';
MessageDlg(S, mtInformation, [mbOk], 0, mbOK);
end;
如果是负数,那么由于byte是无符号的,所以会自动变成整数,将>127
Byte 0 - 255范围没区别。