宇宙中最强悍的繁简转换代码

时间:2010-01-29 08:56:08  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: />usesClasses, Windows;typeTGBBIG5Convert = class(TObject)publicclass function BIG5ToGB(BIG5Str : String): AnsiString;class function GBToBIG5(GBStr : String): AnsiString;end;implementation{******************************** TGBBIG5Convert ********************************
  正文:非常简练的简繁体代码转换程序.

unit UGBBig5Convert;

interface

uses
Classes, Windows;

type
TGBBIG5Convert = class(TObject)
public
class function BIG5ToGB(BIG5Str : String): AnsiString;
class function GBToBIG5(GBStr : String): AnsiString;
end;


implementation

{
******************************** TGBBIG5Convert ********************************
}

class function TGBBIG5Convert.BIG5ToGB(BIG5Str : String): AnsiString;
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
  //String -> PChar
  pBIG5Char := PChar(BIG5Str);
  Len := MultiByteToWideChar(950,0,pBIG5Char,-1,nil,0);
  GetMem(pUniCodeChar,Len*2);
  ZeroMemory(pUniCodeChar,Len*2);
  //Big5 -> UniCode
  MultiByteToWideChar(950,0,pBIG5Char,-1,pUniCodeChar,Len);
  Len := WideCharToMultiByte(936,0,pUniCodeChar,-1,nil,0,nil,nil);
  GetMem(pGBCHTChar,Len*2);
  GetMem(pGBCHSChar,Len*2);
  ZeroMemory(pGBCHTChar,Len*2);
  ZeroMemory(pGBCHSChar,Len*2);
  //UniCode->GB CHT
  WideCharToMultiByte(936,0,pUniCodeChar,-1,pGBCHTChar,Len,nil,nil);
  //GB CHT -> GB CHS
  LCMaphotoshop/ target=_blank class=infotextkey>pstring($804,LCMAP_SIMPLIFIED_CHINESE,pGBCHTChar,-1,pGBCHSChar,Len);
  Result := String(pGBCHSChar);
  FreeMem(pGBCHTChar);
  FreeMem(pGBCHSChar);
  FreeMem(pUniCodeChar);
end;

class function TGBBIG5Convert.GBToBIG5(GBStr : String): AnsiString;
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
pUniCodeChar: PWideChar;
pBIG5Char: 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);
  GetMem(pUniCodeChar,Len*2);
  ZeroMemory(pUniCodeChar,Len*2);
  //GB CHT -> UniCode
  MultiByteToWideChar(936,0,pGBCHTChar,-1,pUniCodeChar,Len*2);
  Len := WideCharToMultiByte(950,0,pUniCodeChar,-1,nil,0,nil,nil);
  GetMem(pBIG5Char,Len);
  ZeroMemory(pBIG5Char,Len);
  //UniCode -> Big5
  WideCharToMultiByte(950,0,pUniCodeChar,-1,pBIG5Char,Len,nil,nil);
  Result := String(pBIG5Char);
  FreeMem(pBIG5Char);
  FreeMem(pGBCHTChar);
  FreeMem(pUniCodeChar);
end;


end.

宇宙中最强悍的繁简转换代码》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12578.html


关键字:

关于《宇宙中最强悍的繁简转换代码》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td