例:string str="大家好!888";
 //转成类似这样的编码:&ZwlRc2WHTvY-谢谢大家了!!

解决方案 »

  1.   


    using System;
    using System.Text;class UTF7EncodingExample {
        public static void Main() {
            // Create a UTF-7 encoding.
            UTF7Encoding utf7 = new UTF7Encoding();        // A Unicode string with two characters outside a 7-bit code range.
            String unicodeString =
                "This Unicode string contains two characters " +
                "with codes outside a 7-bit code range, " +
                "Pi (\u03a0) and Sigma (\u03a3).";
            Console.WriteLine("Original string:");
            Console.WriteLine(unicodeString);        // Encode the string.
            Byte[] encodedBytes = utf7.GetBytes(unicodeString);
            Console.WriteLine();
            Console.WriteLine("Encoded bytes:");
            foreach (Byte b in encodedBytes) {
                Console.Write("[{0}]", b);
            }
            Console.WriteLine();        // Decode bytes back to string.
            // Notice Pi and Sigma characters are still present.
            String decodedString = utf7.GetString(encodedBytes);
            Console.WriteLine();
            Console.WriteLine("Decoded bytes:");
            Console.WriteLine(decodedString);
        }
    }
      

  2.   

    楼主要将什么格式的编码转换为UTF7?
    不同格式的编码要修改这里
     Byte[] encodedBytes = utf7.GetBytes(unicodeString);——》
     Byte[] encodedBytes =Encoding.GetEncoding("GB2312").GetBytes(unicodeString);
    或者
     Byte[] encodedBytes =Encoding.Defalut.GetBytes(unicodeString)
    这样到下面utf7.GetString(encodedBytes);才是utf7转换的编码
      

  3.   

    string str = new StreamReader("文件的路径", System.Text.Encoding.UTF7).ReadToEnd();