Delphi character and string [6]

Source: Internet
Author: User
Tags chr ord

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.