利用操作系统API进行中文内码转换和进行简体与繁体转换(GB、Big5、GBK)(注:简体和和繁体都是GB编码,只是字型不相同)(转换速度超快,Cool !)

  • 主题发起人 主题发起人 apower
  • 开始时间 开始时间
A

apower

Unregistered / Unconfirmed
GUEST, unregistred user!
利用操作系统API进行中文内码转换和进行简体与繁体转换(GB、Big5、GBK)(注:简体和和繁体都是GB编码,只是字型不相同)(转换速度超快,Cool !) ( 积分: 50 )<br />{单元功能:利用操作系统API进行中文内码转换和进行简体与繁体转换(GB、Big5、GBK)((注:简体和和繁体都是GB编码,只是字型不相同) (转换速度超快,Cool !)
代码收集整理人:李春德
整理日期:2005年8月4日
}
uses
windows;

function Big52GB(BIG5Str : String): AnsiString;
{进行big5转GB内码}
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
//String -&gt; PChar
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950,0,pBIG5Char,-1,nil,0);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
//Big5 -&gt; 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-&gt;GB CHT
WideCharToMultiByte(936,0,pUniCodeChar,-1,pGBCHTChar,Len,nil,nil);
//GB CHT -&gt; GB CHS
LCMapString($804,LCMAP_SIMPLIFIED_CHINESE,pGBCHTChar,-1,pGBCHSChar,Len);
Result := String(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;

function GB2Big5(GBStr : String): AnsiString;
{进行GB转BIG5内码}
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 -&gt; GB CHT
LCMapString($804,LCMAP_TRADITIONAL_CHINESE,pGBCHSChar,-1,pGBCHTChar,Len*2);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
//GB CHT -&gt; 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 -&gt; Big5
WideCharToMultiByte(950,0,pUniCodeChar,-1,pBIG5Char,Len,nil,nil);
Result := String(pBIG5Char);
FreeMem(pBIG5Char);
FreeMem(pGBCHTChar);
FreeMem(pUniCodeChar);
end;

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 -&gt; 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 -&gt; GB CHT
LCMapString($804,LCMAP_TRADITIONAL_CHINESE,pGBCHSChar,-1,pGBCHTChar,Len*2);
Result := String(pGBCHTChar);
FreeMem(pGBCHTChar);
//FreeMem(pGBCHSChar);
end;
 
{单元功能:利用操作系统API进行中文内码转换和进行简体与繁体转换(GB、Big5、GBK)((注:简体和和繁体都是GB编码,只是字型不相同) (转换速度超快,Cool !)
代码收集整理人:李春德
整理日期:2005年8月4日
}
uses
windows;

function Big52GB(BIG5Str : String): AnsiString;
{进行big5转GB内码}
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
//String -&gt; PChar
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950,0,pBIG5Char,-1,nil,0);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
//Big5 -&gt; 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-&gt;GB CHT
WideCharToMultiByte(936,0,pUniCodeChar,-1,pGBCHTChar,Len,nil,nil);
//GB CHT -&gt; GB CHS
LCMapString($804,LCMAP_SIMPLIFIED_CHINESE,pGBCHTChar,-1,pGBCHSChar,Len);
Result := String(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;

function GB2Big5(GBStr : String): AnsiString;
{进行GB转BIG5内码}
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 -&gt; GB CHT
LCMapString($804,LCMAP_TRADITIONAL_CHINESE,pGBCHSChar,-1,pGBCHTChar,Len*2);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
//GB CHT -&gt; 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 -&gt; Big5
WideCharToMultiByte(950,0,pUniCodeChar,-1,pBIG5Char,Len,nil,nil);
Result := String(pBIG5Char);
FreeMem(pBIG5Char);
FreeMem(pGBCHTChar);
FreeMem(pUniCodeChar);
end;

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 -&gt; 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 -&gt; GB CHT
LCMapString($804,LCMAP_TRADITIONAL_CHINESE,pGBCHSChar,-1,pGBCHTChar,Len*2);
Result := String(pGBCHTChar);
FreeMem(pGBCHTChar);
//FreeMem(pGBCHSChar);
end;
 
apower兄:

我正找相關的資料啊,試試看,如果可以的話,有分送,^_^
 
后退
顶部