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.