请问如何使用MultiByteToWideChar和WideCharToMultiByte将iso8859-1转换成gb2312编码? ( 积分: 100 )

  • 主题发起人 主题发起人 leemanzhuo
  • 开始时间 开始时间
L

leemanzhuo

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