同题

解决方案 »

  1.   

    public bool decodeQP(String strSrc, ref String result)//对quoted-printable编码strSrc进行解码,解码结果保存在result中,成功返回true
    {
    bool flag = true;
    result = "";
    try
    {
    char ch, ch1, ch2;
    int chint, chint1, chint2;
    if (strSrc != null)
    {
    strSrc = strSrc.Replace("=09", "");
    strSrc = strSrc.Replace("==", "=");
    }
    char[] hz = strSrc.ToCharArray(); byte[] bytes = new byte[2];
    result = "";
    for (int i = 0; i < strSrc.Length; i++)
    {
    ch = hz[i];
    if (ch == '=')
    {
    i++;
    ch1 = hz[i];
    if (ch1 == 13 || ch1 == 10)
    {
    //i++;
    continue;
    }
    i++;
    ch2 = hz[i];
    if (ch1 == '3' && ch2 == 'D')
    {
    //System.Text.Encoding.GetEncoding(54936).GetString(b);
    result += "=";
    continue;
    }
    else
    { if (ch1>'9')
    {
    chint1=(ch1-'A'+10)*16;
    }
    else
    {
    chint1=(ch1-'0')*16;
    }
    if (ch2>'9')
    {
    chint2=ch2-'A'+10;
    }
    else
    {
    chint2=ch2-'0';
    } ch = hz[i+1];
    if (ch != '=')
    {
    result += ch1.ToString();
    result += ch2.ToString();
    continue;
    }
    chint = chint1 + chint2;
    bytes[0] = Convert.ToByte(chint);
    i = i + 2;
    ch1 = hz[i];
    while (ch1 == 13 || ch1 == 10)
    {
    i++;
    i++;
    ch1 = hz[i];
    }
    if (ch1 == '=')
    {
    i++;
    ch1 = hz[i];
    }
    i++;
    ch2 = hz[i]; if (ch1>'9')
    {
    chint1=(ch1-'A'+10)*16;
    }
    else
    {
    chint1=(ch1-'0')*16;
    }
    if (ch2>'9')
    {
    chint2=ch2-'A'+10;
    }
    else
    {
    chint2=ch2-'0';
    } chint = chint1 + chint2;
    bytes[1] = Convert.ToByte(chint); result += System.Text.Encoding.GetEncoding(54936).GetString(bytes); } }
    else
    {
    result += ch.ToString();
    }
    }
    }
    catch
    {
    flag = false;
    }
    return flag;
    }