请问c#如何对quote-printable编码的字符串进行解码?

dwg_cn 2003-08-27 01:45:23
比如下面的一段

test=D7=AA=B7=A2: =CD=CC=D5=E2=CA=C7=D2=BB=B8=F6=D5=E6=CA=B5=B5=C4=B9=CA=CA=C2=A3=A1(=BA=A7=C8=CB=A8=DB=A3=A1)
...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sbwgi 2004-02-17
  • 打赏
  • 举报
回复
mark
dwg_cn 2003-08-27
  • 打赏
  • 举报
回复
如果可以的话能把编码的部分也放出吗?谢谢了:-)
webxiaobj 2003-08-27
  • 打赏
  • 举报
回复
/// <summary>
/// quoted-printable解码程序.
/// </summary>
/// <param name="encoding">解码目标字符集</param>
/// <param name="data">需要解码的字符串</param>
/// <returns></returns>
public static string QDecode(System.Text.Encoding encoding,string data)
{
MemoryStream strm = new MemoryStream(System.Text.Encoding.Default.GetBytes(data));

int b = strm.ReadByte();

MemoryStream dStrm = new MemoryStream();

while(b > -1){
// Hex eg. =E4
if(b == '='){
byte[] buf = new byte[2];
strm.Read(buf,0,2);
if(!(buf[0] == '\r' && buf[1] == '\n')){
int val = int.Parse(System.Text.Encoding.Default.GetString(buf),System.Globalization.NumberStyles.HexNumber);
//int val = int.Parse(System.Text.Encoding.Default.GetString(buf));
byte[] temp=new Byte[]{(byte)val};
dStrm.Write(temp,0,temp.Length);
}
}
else{
string encodedChar = encoding.GetString(new byte[]{(byte)b});
byte[] d = System.Text.Encoding.Default.GetBytes(encodedChar);
dStrm.Write(d,0,d.Length);
}

b = strm.ReadByte();
}
return encoding.GetString(dStrm.ToArray());
}

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧