string str = "中文";
Encoding.GetEncoding("UTF-8").GetString(str)
你试一试

解决方案 »

  1.   

    用 Encoding.Convert 函数
    可以参看下面代码:
    using System;
    using System.Text;namespace ConvertExample
    {
       class ConvertExampleClass
       {
          static void Main()
          {
             string unicodeString = "This string contains the unicode character Pi(\u03a0)";         // Create two different encodings.
             Encoding ascii = Encoding.ASCII;
             Encoding unicode = Encoding.Unicode;         // Convert the string into a byte[].
             byte[] unicodeBytes = unicode.GetBytes(unicodeString);         // Perform the conversion from one encoding to the other.
             byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
                
             // Convert the new byte[] into a char[] and then into a string.
             // This is a slightly different approach to converting to illustrate
             // the use of GetCharCount/GetChars.
             char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
             ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
             string asciiString = new string(asciiChars);         // Display the strings created before and after the conversion.
             Console.WriteLine("Original string: {0}", unicodeString);
             Console.WriteLine("Ascii converted string: {0}", asciiString);
          }
       }
    }
      

  2.   

    System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();byte[] codes = utf8.GetBytes(str);
      

  3.   

    大家的方法我都试过了,没一个行的。最后的结果我想要字符串string,不是byte[]。
    将byte[]转到字符串后又变成普通的字符串了。大家继续,谢谢
      

  4.   

    I See,try:System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();byte[] codes = utf8.GetBytes(str);StringBuilder builder = new StringBuilder();
    for( int i=0;i<codes.Length;i++ )
    builder.Append( codes[i].ToString("X2") );
    string strCode = builder.ToString();
      

  5.   

    tim兄,还是不行呀
    偶原来的串是"中文"用你的方法后变成"E4B8ADE69687"可是输出后又照原样"E4B8ADE69687"出来了。另外,如果直接用“中文”输出,结果是"-"
      

  6.   

    偶用的是这个方法,其实第一个参数决定输出文本的编码格式,不能修改,固定的。
    ses.SendText ("MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\n",strCode,IM_MSG_TYPE.IM_MSG_TYPE_ALL_RESULTS);输出英文和数字全正常,就是中文不行。。
      

  7.   

    参考一下下面的介绍: 下面的示例演示了如何使用 UTF8Encoding 对 Unicode 字符串进行编码,并将它们存储在字节数组 encodedBytes 中。请注意,将 encodedBytes 重新解码为字符串时不会丢失数据。using System;
    using System.Text;class UTF8EncodingExample {
        public static void Main() {
            // Create a UTF-8 encoding.
            UTF8Encoding utf8 = new UTF8Encoding();
            
            // A Unicode string with two characters outside an 8-bit code range.
            String unicodeString =
                "This unicode string contains two characters " +
                "with codes outside an 8-bit code range, " +
                "Pi (\u03a0) and Sigma (\u03a3).";
            Console.WriteLine("Original string:");
            Console.WriteLine(unicodeString);        // Encode the string.
            Byte[] encodedBytes = utf8.GetBytes(unicodeString); // 得到UTF8的字节数组
            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 = utf8.GetString(encodedBytes);  // 将字节数组合成一个字符串
            Console.WriteLine();
            Console.WriteLine("Decoded bytes:");
            Console.WriteLine(decodedString);
        }
    }
      

  8.   

    Encoding.GetEncoding("UTF-8").GetString(str)
      

  9.   

    System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();
    byte[] codes = utf8.GetBytes(str);将byte[]转到字符串后又变成普通的字符串了,你咋转的?
      

  10.   

    Dim s As String = "中文"
    Dim b As byte()b = System.Text.Encoding.Utf8.GetBytes(s)
    s = System.Text.Encoding.Unicode.GetString(b)
      

  11.   

    梦兄,偶咋看不懂你在说什么??
    Convert.tostring(cc,2)cc是啥?2又是啥??
      

  12.   

    大件兄,你的结果也不行,
    "中文"转换后是"&#47332;螖",输出后是"&#47332;"
      

  13.   

    其实并不是很明白你的意思
    看看这,或许对你有用吧:
    http://expert.csdn.net/Expert/topic/1880/1880675.xml?temp=.5347559