Learn about double bytecode and how to get Chinese characters-Reply to "pinezhou"

Source: Internet
Author: User
Problem Source: http://www.cnblogs.com/del/archive/2008/09/05/1284923.html#1818187
{View the double and Unicode codes of the same string} procedure tform1.button1click (Sender: tobject); var str1: ansistring; str2: unicodestring; {string = unicodestring} p: pint; the dual-byte code for begin {"in case" is: bbd2f2cd} str1: = 'In case'; P: = @ str1 [1]; showmessage (inttohex (P ^, 4); // bbd2f2cd {: f2cd; 1: bbd2} {"in case" the corresponding Unicode code is: 4e004e07} str2: = 'in case '; P: = @ str2 [1]; showmessage (inttohex (P ^, 4); // 4e004e07 {tens of thousands: 4e00; 1: 4e00} end; {know double byte code, how to convert to UNICODE: convert two words together} procedure tform1.button2click (Sender: tobject); var str1: ansistring; str2: string; begin setlength (str1, 4 ); pinteger (@ str1 [1]) ^: = $ bbd2f2cd; memo1.lines. add (str1); // In case of str2: = str1; memo1.lines. add (str2); // In case of end; {verbatim conversion} procedure tform1.button3click (Sender: tobject); var str1: ansistring; begin setlength (str1, 2 ); pword (@ str1 [1]) ^: = $ f2cd; memo1.lines. add (str1); // tens of thousands of pword (@ str1 [1]) ^: = $ bbd2; memo1.lines. add (str1); // an end;

  

It seems that the problem has not been solved. Let's try again:

Const gb18030 = 54936; var bytesgb18030: tbytes; {view hex functions} function tohex (P: pbytearray; B: integer): string; var I: integer; begin for I: = 0 to B-1 do result: = inttohex (P ^ [I], 2) + CHR (32) + result; Result: = trimright (result); end; {observing the encoding string stored in gb18030} procedure tform1.button1click (Sender: tobject); var strhex: string; stringstream: tstringstream; begin stringstream: = tstringstream. create ('delphi blog in case ', gb18030); bytesgb18030: = stringstream. bytes; memo1.lines. add (stringstream. datastring); memo1.lines. add (tohex (@ bytesgb18030 [0], length (bytesgb18030); memo1.lines. add (''); stringstream. free; end; {observe the Unicode encoding of the string} procedure tform1.button2click (Sender: tobject); var strhex: string; stringstream: tstringstream; begin stringstream: = tstringstream. create ('delphi blog in case ', tencoding. unicode); memo1.lines. add (stringstream. datastring); memo1.lines. add (tohex (@ stringstream. bytes [0], length (stringstream. bytes); memo1.lines. add (''); stringstream. free; end; {convert bytesgb18030 from the byte array obtained in the previous test to a unicode string} procedure tform1.button3click (Sender: tobject); var stringstream: tstringstream; STR, strhex: string; begin if length (bytesgb18030)

 
(* Test results in Memo: memo1 in case of Delphi blog cd bf A9 B2 20 69 68 70 6C 65 44 20 C4 B5 BB D2 F2 CD in case of Delphi blog 5B A2 53 5A 00 20 00 69 00 68 00 70 00 6c 00 65 00 44 00 20 76 84 4E 00 4E 70 thousand a Delphi blog cd bf A9 B2 20 69 68 70 6C 65 44 20 C4 B5 BB D2 F2 CD in case of Delphi blog 5b a2 53 5A 00 20 00 69 00 68 00 70 00 6C 00 65 00 44 00 20 76 84 4E 00 4E 07 *)

  

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.