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;

    }

posted on 2008-03-18 14:30  天歆  阅读(494)  评论(0编辑  收藏  举报