Conversion of Chinese characters and multi-byte encoding-Reply to "unknown"

Source: Internet
Author: User
Problem Source: http://www.cnblogs.com/del/archive/2008/11/22/1284923.html#1378410

Delphi 2009 uses multi-byte encoding (MBCS) by default. Delphi indicates tencoding. default.

The following is an example of conversion between multi-byte encoding and Chinese characters:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); Procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {Chinese character to multi-byte encoding} procedure tform1.button1click (Sender: tobject); var stream: tstringstream; B: byte; s: string; begin stream: = tstringstream. create ('ours ', tencoding. default); s: = ''; for B in stream. bytes do s: = format ('% S % x', [S, B]); showmessage (s); {ce D2 C3 C7} stream. free; end; {multi-byte encoding to Chinese characters} procedure tform1.button2click (Sender: tobject); var stream: tstringstream; begin stream: = tstringstream. create; stream. size: = 4; stream. bytes [0]: = $ CE; stream. bytes [1]: = $ D2; stream. bytes [2]: = $ C3; stream. bytes [3]: = $ C7; showmessage (stream. datastring); {We} stream. free; end; {convert multi-byte encoded strings to Chinese characters} procedure tform1.button3click (Sender: tobject); var STR: ansistring; stream: tstringstream; I: integer; begin STR: = 'ced2c3c7'; stream: = tstringstream. create; stream. size: = length (STR) Div 2; for I: = 1 to length (STR) do if odd (I) Then stream. bytes [I Div 2]: = strtointdef (Concat (#36, STR [I], STR [I + 1]), 0); showmessage (stream. datastring); {We} stream. free; 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.