Conversion of Delphi Character and string [6]-Char (Ansichar), Widechar and its encoding
Conversion of the Char type to its encoded value:
var
b: Byte;
c: Char;
begin
b := Ord('A'); {返回: 65}
b := Ord(#65); {返回: 65}
b := Ord($41); {返回: 65}
b := Ord(#$41); {返回: 65}
b := Byte('A'); {返回: 65}
b := Byte(#65); {返回: 65}
b := Byte($41); {返回: 65}
b := Byte(#$41); {返回: 65}
c := Chr(65); {返回: A }
c := Chr($41); {返回: A }
c := Char(65); {返回: A }
c := Char($41); {返回: A }
end;
The conversion of Widechar type and its encoded value; The UniCode encoding range of Chinese characters is: $4e00. $9fa5
var
w : Word;
c : WideChar;
ws: WideString;
s : string;
begin
{准备工作}
ws := '万一';
c := ws[1];
//ShowMessage(c); {万}
{从汉字到 UniCode 编码}
w := Ord(c); {返回十进制数 : 19975}
w := Word(c); {返回十进制数 : 19975}
s := Format('%.4x',[Ord(c)]); {返回十六进制的字符串: 4E07 }
s := IntToHex(Ord(c), 4); {返回十六进制的字符串: 4E07 }
{从 UniCode 编码到汉字}
c := #19975; {万}
c := #$4E07; {万}
c := #$4e07; {万}
c := WideChar(19975); {万}
c := WideChar($4E07); {万}
end;