繁体与简体之间的转换

繁体与简体之间的转换

DELPHI XE5测试通过  http://download.csdn.net/detail/teststudio/6464553
  
繁体与简体之间的转换
 
繁体与简体之间的转换
 
 
unit SimpleConvert;

interface

uses

  Classes, Windows;

type

  TTraditional = class(TObject)

  public

    function ConvertComplex(Text: String): AnsiString;

    function ConvertSimple(Text: String): AnsiString;

  end;

implementation

{ 进行GBK繁体转简体 }

function TTraditional.ConvertSimple(Text: String): AnsiString;

Var

  Len: Integer;

  pGBCHTChar: PChar;

  pGBCHSChar: PChar;

Begin

  pGBCHTChar := PChar(Text);

  Len := MultiByteToWideChar(936, 0, pansichar(pGBCHTChar), -1, Nil, 0);

  GetMem(pGBCHSChar, Len * 2 + 1);

  ZeroMemory(pGBCHSChar, Len * 2 + 1);

  LCMapString($804, LCMAP_SIMPLIFIED_CHINESE, pGBCHTChar, -1,

    pGBCHSChar, Len * 2);

  Result := String(pGBCHSChar);

  FreeMem(pGBCHSChar);

end;

{ 进行GBK简体转繁体 }

function TTraditional.ConvertComplex(Text: String): AnsiString;

Var

  Len: Integer;

  pGBCHTChar: PChar;

  pGBCHSChar: PChar;

Begin

  pGBCHSChar := PChar(Text);

  Len := MultiByteToWideChar(936, 0, pansichar(pGBCHSChar), -1, Nil, 0);

  GetMem(pGBCHTChar, Len * 2 + 1);

  ZeroMemory(pGBCHTChar, Len * 2 + 1);

  LCMapString($804, LCMAP_TRADITIONAL_CHINESE, pGBCHSChar, -1,

    pGBCHTChar, Len * 2);

  Result := String(pGBCHTChar);

  FreeMem(pGBCHTChar);

end;

end.

 

 
使用
uses SimpleConvert;

procedure TForm1.Button1Click(Sender: TObject);

var

  a: TTraditional;

begin

  a := TTraditional.Create;

  Caption := a.ConvertSimple(Edit1.Text);

end;

procedure TForm1.Button2Click(Sender: TObject);

var

  a: TTraditional;

begin

  a := TTraditional.Create;

  Caption := a.ConvertComplex(Edit1.Text);

end;

 





你可能感兴趣的:(转换)