C# 解quoted-printable编码的方法

    private string DecodeQP(string code,string charset)
    {
        ArrayList aryBytes = new ArrayList();
        char ch;
        int i = 0;
        while (i < code.Length)
        {
            ch = code[i];
            if (ch == \’=\’)
            {
                if (code.Substring(i, 3) == “=\r\n”)
                {
                    i += 3;
                }
                else
                {
                    string tmp = code.Substring(i + 1, 2);
                    aryBytes.Add((byte)int.Parse(tmp, System.Globalization.NumberStyles.HexNumber));
                    i += 3;
                }
            }
            else
            {
                aryBytes.Add((byte)ch);
                i++;
            }
        }
        byte[] decodeBytes = new byte[aryBytes.Count];
        for (int j = 0; j < aryBytes.Count; j++)
        {
            decodeBytes[j] = (byte)aryBytes[j];
        }
        //string decode = Encoding.Default.GetString(decodeBytes);
        string decode=Encoding.GetEncoding(charset).GetString(decodeBytes);
        return decode;

    }

版权声明:本文为shaomei-21原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/shaomei-21/articles/1111577.html