Z
zpselect
Unregistered / Unconfirmed
GUEST, unregistred user!
如题,我在网上找了一些简体转繁体的代码,可是在繁体操作系统下运行也是乱码,请问这是怎么回事?有的人说,简体系统的字体与繁体系统下的字体不同,所以转换过来是乱码!
我把代码贴出来,望各位指点!
function TForm1.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 -> 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;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption:=GB2Big5(Label1.Caption);
end;
注意:Label1.Caption为:中华人民共和国
我把代码贴出来,望各位指点!
function TForm1.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 -> 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;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption:=GB2Big5(Label1.Caption);
end;
注意:Label1.Caption为:中华人民共和国