函数返回byte*,如何转换成字符串????

解决方案 »

  1.   

    http://www.cnblogs.com/ewyb/archive/2009/12/10/1621020.html
      

  2.   

    http://msdn.microsoft.com/zh-cn/library/ms146632.aspxMarshal.Copy 方法 (IntPtr, Char[], Int32, Int32)将数据从非托管内存指针复制到托管字符数组。  语法public static void Copy(
    IntPtr source,
    char[] destination,
    int startIndex,
    int length
    )
      

  3.   

    byte[] to string  byte[] bytes=....
      string str = Encoding.Default.GetString(bytes);string to byte[]string str=...
    byte[] bytes = Encoding.Default.GetBytes(str);
      

  4.   


    string str = "你好你好哦";
                byte[] buff = System.Text.Encoding.Unicode.GetBytes(str);
                byte[] trans = new byte[256];
                unsafe
                {
                    fixed (byte* p = &buff[0])
                    {
                        for (int i = 0; i < 256; i++)
                        {
                            trans[i] = *(p+i);
                        }
                        string str1 = System.Text.Encoding.Unicode.GetString(trans);
                        MessageBox.Show("str" + "的值是:" + str + "\r\n" + "str1" + "的值是:" + str1);
                    }
                }请问这个思路正确???
      

  5.   

      public string BytesToString(byte[] source, int start, int len)
            {            string result ="";
                result = Encoding.ASCII.GetString(source, start, len);
            
                return result;
            }
      

  6.   

    首先要知道 byte 表示的字符串用哪种编码,常用的有 GB2312, UTF-8, UNICODE 等。
    然后用 Encoding.UTF8.GetString() 方法。