Delphi单元文件之-简体繁体互转

2991人阅读 评论(0) 收藏 举报

Function GBCht2Chs(GBStr: String): AnsiString; {GBK繁体转简体}
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;
{进行GBK繁体转简体}
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;
{进行GBK简体转繁体}
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.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2322068次
    • 积分:24362
    • 等级:
    • 排名:第253名
    • 原创:401篇
    • 转载:102篇
    • 译文:4篇
    • 评论:1292条
    博客专栏
    最新评论