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

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.

你可能感兴趣的:(Delphi)