D
dedragon
Unregistered / Unconfirmed
GUEST, unregistred user!
我需要做的是把邮件编码里的QP码转换为GB简体中文,下面的代码已经可以把全部中文关于全角的QP编码转换为GB码了,但对于中文里带有的半角英文和符号不能正确编码,请指教如何解决。<br>如=?gb2312?Q?=B4=F3=B4=F3=B7=F9=B6=C8=B5=C4?=B4=F3=B7=F9=B6=C8=B6=F6=C8=C8/=B4=F3=B7=F9=B6=C8?=的编码应该为<br>“大大幅度的?大幅度饿热/大幅度”<br>,但因为?和/的存在而无法进行编码,请指教<br><br>unit QPToGB2312;<br><br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br> <br>function HexToChar(HexStr: string): Char;<br>function FiltString(QPtmp: string): string;<br><br>implementation<br><br>//将十六进制数字符串转换为单一字符<br>function HexToChar(HexStr: string): Char;<br>var<br> TempChr: Char;<br> TempInt: Integer;<br>begin<br> TempChr := HexStr[1];<br> if TempChr > '9' then<br> TempInt := ord(TempChr) - 65 + 10<br> else<br> TempInt := ord(TempChr) - 48;<br> TempInt := TempInt * 16;<br> TempChr := HexStr[2];<br> if TempChr > '9' then<br> TempInt := TempInt + ord(TempChr) - 65 + 10<br> else<br> TempInt := TempInt + ord(TempChr) - 48;<br> Result := Chr(TempInt);<br>end;<br><br>function FiltString(QPtmp: string): string;<br>var<br> TmpString, GBString: string; //读取需要转换为字符的2个十六位字符串<br> I, Times, TmpPos, CopyBegin, CopyLen: Integer;<br> TmpChar:Char;<br>begin<br> Result := '';<br> TmpPos := Pos('?Q?', QPtmp);<br> if TmpPos <> 0 then begin<br> //去掉前三个?前面的内容<br> for I := 1 to 3 do begin<br> TmpPos := Pos('?', QPtmp);<br> CopyBegin := TmpPos + 1;<br> CopyLen := length(QPtmp) - CopyBegin + 1;<br> QPtmp := copy(QPtmp, CopyBegin, CopyLen);<br> end;<br> Times := CopyLen div 3;<br> for I := 1 to Times do begin<br> //查找=的存在,=以后的二个16进制字符串转换为字符<br> TmpPos := Pos('=', QPtmp);<br> CopyBegin := TmpPos + 1;<br> CopyLen := length(QPtmp) - CopyBegin + 1;<br> TmpString := copy(QPtmp, CopyBegin, 2);<br> GBString := HexToChar(TmpString);<br><br> QPtmp := copy(QPtmp, CopyBegin, CopyLen);<br> Result := Result + GBString;<br> end;<br> end<br> else<br> Result := QPtmp;<br>end;<br><br>end.<br>