请教一下关于QP码转换为GB码(100分)

  • 主题发起人 主题发起人 dedragon
  • 开始时间 开始时间
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>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br>&nbsp; <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>&nbsp; TempChr: Char;<br>&nbsp; TempInt: Integer;<br>begin<br>&nbsp; TempChr := HexStr[1];<br>&nbsp; if TempChr &gt; '9' then<br>&nbsp; &nbsp; TempInt := ord(TempChr) - 65 + 10<br>&nbsp; else<br>&nbsp; &nbsp; TempInt := ord(TempChr) - 48;<br>&nbsp; TempInt := TempInt * 16;<br>&nbsp; TempChr := HexStr[2];<br>&nbsp; if TempChr &gt; '9' then<br>&nbsp; &nbsp; TempInt := TempInt + ord(TempChr) - 65 + 10<br>&nbsp; else<br>&nbsp; &nbsp; TempInt := TempInt + ord(TempChr) - 48;<br>&nbsp; Result := Chr(TempInt);<br>end;<br><br>function FiltString(QPtmp: string): string;<br>var<br>&nbsp; TmpString, GBString: string; //读取需要转换为字符的2个十六位字符串<br>&nbsp; I, Times, TmpPos, CopyBegin, CopyLen: Integer;<br>&nbsp; TmpChar:Char;<br>begin<br>&nbsp; Result := '';<br>&nbsp; TmpPos := Pos('?Q?', QPtmp);<br>&nbsp; if TmpPos &lt;&gt; 0 then begin<br>&nbsp; &nbsp; //去掉前三个?前面的内容<br>&nbsp; &nbsp; for I := 1 to 3 do begin<br>&nbsp; &nbsp; &nbsp; TmpPos := Pos('?', QPtmp);<br>&nbsp; &nbsp; &nbsp; CopyBegin := TmpPos + 1;<br>&nbsp; &nbsp; &nbsp; CopyLen := length(QPtmp) - CopyBegin + 1;<br>&nbsp; &nbsp; &nbsp; QPtmp := copy(QPtmp, CopyBegin, CopyLen);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Times := CopyLen div 3;<br>&nbsp; &nbsp; for I := 1 to Times do begin<br>&nbsp; &nbsp; &nbsp; //查找=的存在,=以后的二个16进制字符串转换为字符<br>&nbsp; &nbsp; &nbsp; TmpPos := Pos('=', QPtmp);<br>&nbsp; &nbsp; &nbsp; CopyBegin := TmpPos + 1;<br>&nbsp; &nbsp; &nbsp; CopyLen := length(QPtmp) - CopyBegin + 1;<br>&nbsp; &nbsp; &nbsp; TmpString := copy(QPtmp, CopyBegin, 2);<br>&nbsp; &nbsp; &nbsp; GBString := HexToChar(TmpString);<br><br>&nbsp; &nbsp; &nbsp; QPtmp := copy(QPtmp, CopyBegin, CopyLen);<br>&nbsp; &nbsp; &nbsp; Result := Result + GBString;<br>&nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; Result := QPtmp;<br>end;<br><br>end.<br>
 
使用IdDecoderQuotedPrintable控件<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; s: string;<br>begin<br>&nbsp; s := '=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>&nbsp; s := IdDecoderQuotedPrintable1.DecodeString(s);<br>&nbsp; showmessage(s);<br>end;<br><br>你的三个问题我都答了,呵呵,快给分……[:D]
 
呵呵,这个问题在我发出帖子的第二个星期就已经解决了,看这没人理就一直没管,等斑竹结束,既然还有人答就给你分咯
 
后退
顶部