日期:2014-05-19  浏览次数:20979 次

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

------解决方案--------------------
//硬写一个也不难...
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 路过 "));
}