Delphi unit file-conversion between simplified and traditional Chinese characters

Source: Internet
Author: User

Function gbcht2chs (gbstr: string): ansistring; {GBK traditional to simplified}
VaR
Len: integer;
Pgbchtchar: pchar;
Pgbchschar: pchar;
Begin
Pgbchtchar: = pchar (gbstr );
Len: = sizeof (pgbchtchar );
Getmem (pgbchschar, Len + 1 );
Zeromemory (pgbchschar, Len + 1 );

// Gb chs-> GB CHT
Lcmapstring ($804, lcmap_simplified_chinese, pgbchtchar,-1, pgbchschar, 2147483647 );

Result: = string (pgbchschar );
Freemem (pgbchschar );
End;

//----------------------------------------------

Procedure tform1.button1click (Sender: tobject );
Begin
Memo2.text: = gbcht2chs (memo1.text );
End;

Unit big5togb;
Interface

Uses
Windows;

Function gbcht2chs (gbstr: string): ansistring;
Function gbchs2cht (gbstr: string): ansistring;

Implementation

Function gbcht2chs (gbstr: string): ansistring;
{Convert GBK to simplified Chinese}
VaR
Len: integer;
Pgbchtchar: pchar;
Pgbchschar: pchar;
Begin
Pgbchtchar: = pchar (gbstr );
Len: = multibytetowidechar (936, 0, pgbchtchar,-1, nil, 0 );
Getmem (pgbchschar, Len * 2 + 1 );
Zeromemory (pgbchschar, Len * 2 + 1 );
// Gb chs-> GB CHT
Lcmapstring ($804, lcmap_simplified_chinese, pgbchtchar,-1, pgbchschar, Len * 2 );
Result: = string (pgbchschar );
// Freemem (pgbchtchar );
Freemem (pgbchschar );
End;

Function gbchs2cht (gbstr: string): ansistring;
{Convert GBK to traditional Chinese}
VaR
Len: integer;
Pgbchtchar: pchar;
Pgbchschar: pchar;
Begin
Pgbchschar: = pchar (gbstr );
Len: = multibytetowidechar (936, 0, pgbchschar,-1, nil, 0 );
Getmem (pgbchtchar, Len * 2 + 1 );
Zeromemory (pgbchtchar, Len * 2 + 1 );
// Gb chs-> GB CHT
Lcmapstring ($804, lcmap_traditional_chinese, pgbchschar,-1, pgbchtchar, Len * 2 );
Result: = string (pgbchtchar );
Freemem (pgbchtchar );
// Freemem (pgbchschar );
End;
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.