请各位发个邮件中quoted printable的编码函数,c#的,不要解码,只要编码的~

liuguozhong 2007-03-20 08:49:52
如题,谢谢了~
...全文
242 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2007-03-20
  • 打赏
  • 举报
回复
//硬写一个也不难...
using System.Collections;
using System.Globalization;

public string QuotedPrintableEncode(string AText) // QP编码
{
string Result = "";
byte[] vBuffer = Encoding.Default.GetBytes(AText);
foreach(byte vByte in vBuffer)
// 可见字符并非"="(#61)
if ((vByte >= 33 && vByte <= 60) || (vByte >= 62 && vByte <= 126))
Result += (char)vByte;
else Result += "=" + vByte.ToString("X2");
return Result;
}

public static string QuotedPrintableDecode(string ACode) // 解码
{
ArrayList vBuffer = new ArrayList();

for(int i = 0; i < ACode.Length; i++)
{
if (ACode[i] == '=')
{
i++;
if (ACode[i] != '\r')
{
byte vByte;
if (byte.TryParse(ACode.Substring(i, 2),
NumberStyles.HexNumber, null, out vByte))
vBuffer.Add(vByte);
}
i++;
}
else if (ACode[i] != '\n') vBuffer.Add((byte)ACode[i]);
}
return Encoding.Default.GetString((byte[])vBuffer.ToArray(typeof(byte)));
}

private void button1_Click(object sender, EventArgs e)
{
Text = QuotedPrintableDecode(QuotedPrintableEncode("zswang 路过"));
}
liuguozhong 2007-03-20
  • 打赏
  • 举报
回复
zswang(伴水清清)(专家门诊清洁工) :

先谢过,可是我要字符串转化为qp编码呢~
王集鹄 2007-03-20
  • 打赏
  • 举报
回复
附件里可以指定编码方式,参考:

Attachment vAttachment = new Attachment("yourfile");
vAttachment.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
liuguozhong 2007-03-20
  • 打赏
  • 举报
回复
50分没人要啊~
richard530 2007-03-20
  • 打赏
  • 举报
回复
up~
liuguozhong 2007-03-20
  • 打赏
  • 举报
回复
再顶一下,怎么没有人帮忙呀~
liuguozhong 2007-03-20
  • 打赏
  • 举报
回复
人工置顶~
liuguozhong 2007-03-20
  • 打赏
  • 举报
回复
顶一下,谢谢了~
liuguozhong 2007-03-20
  • 打赏
  • 举报
回复
感谢~

110,535

社区成员

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

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

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