L
leemanzhuo
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个函数,想将iso8859-1转换成gb2321显示出来,如“&#20581;&#21147;&#22763;”,转换结果是:“健力士”,但是不成功,出来的还是iso8859-1<br><br>代码如下:<br>C88592GB(C8859Char: String): AnsiString;<br>var<br> Len: Integer;<br> p8859Char: PChar;<br> pGBCHSChar: PChar;<br> pUniCodeChar: PWideChar;<br>begin<br> //String -> PChar<br> p8859Char:= PChar(C8859Char);<br> Len := MultiByteToWideChar(28591,0,p8859Char,-1,nil,0);<br> GetMem(pUniCodeChar,Len*2);<br> ZeroMemory(pUniCodeChar,Len*2);<br> //8859 -> UniCode<br> MultiByteToWideChar(28591,0,p8859Char,-1,pUniCodeChar,Len);<br> Len := WideCharToMultiByte(936,0,pUniCodeChar,-1,nil,0,nil,nil);<br> GetMem(pGBCHSChar,Len*2);<br> ZeroMemory(pGBCHSChar,Len*2);<br> //UniCode->GB CHS<br> WideCharToMultiByte(936,0,pUniCodeChar,-1,pGBCHSChar,Len,nil,nil);<br> Result := String(pGBCHSChar);<br> FreeMem(pGBCHSChar);<br> FreeMem(pUniCodeChar);<br>end;<br><br>不知道错在哪里,望指教。