求quoted-printable解码代码片断

ChinaSunFire 2004-04-28 02:19:07
求quoted-printable解码代码
...全文
69 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmdelove 2004-04-28
  • 打赏
  • 举报
回复
/// <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.ASCII.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);

// <CRLF> followed by =, it's splitted line
if(!(buf[0] == '\r' && buf[1] == '\n')){
try{
int val = int.Parse(System.Text.Encoding.ASCII.GetString(buf),System.Globalization.NumberStyles.HexNumber);
string encodedChar = encoding.GetString(new byte[]{(byte)val});
byte[] d = System.Text.Encoding.Unicode.GetBytes(encodedChar);
dStrm.Write(d,0,d.Length);
}
catch{ // If worng hex value, just skip this chars
}
}
}
else{
string encodedChar = encoding.GetString(new byte[]{(byte)b});
byte[] d = System.Text.Encoding.Unicode.GetBytes(encodedChar);
dStrm.Write(d,0,d.Length);
}

b = strm.ReadByte();
}

return System.Text.Encoding.Unicode.GetString(dStrm.ToArray());
}


110,536

社区成员

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

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

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