在C#中,有没有提供一种方法,可以将文本转换为二进制,同样要将二进制转换为文本?

解决方案 »

  1.   

    我知道可以从string或者char或者stream用readbytes或者getbytes等方法转成二进制流,反过来应该也可以就是忘记了
      

  2.   

    你先要搞清楚...任何数据都是二进制,包括文本...所谓文本只是特定字符编码的二进制数据....NET中由System.Text.Encoding类提供特定字符集编码的字符编码及解码...
      

  3.   

     //二进制转字符串:      
        private string ConvertToString(byte[] thebyte)   
        {   
            char[] Chars = new char[System.Text.Encoding.Default.GetCharCount(thebyte, 0, thebyte.Length)];   
            System.Text.Encoding.Default.GetChars(thebyte, 0, thebyte.Length, Chars, 0);   
            string newString = new string(Chars);   
            return newString;   
        }   
      
        //字符串转二进制:      
        private byte[] ConvertToByte(string theString)   
        {   
            byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);   
            return byteStream;   
        }   
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/llddyy123wq/archive/2010/05/16/5597516.aspx
      

  4.   

    byte[] xx = Encoding.GetEncoding("GB2312").GetBytes(string s) 是获得字符串的二进制流的。
    string s = Encoding.GetEncoding("GB2312").GetSt1ring(byte[] xx) 是反向的
      

  5.   

    //二进制转字符串:   
      private string ConvertToString(byte[] thebyte)   
      {   
      char[] Chars = new char[System.Text.Encoding.Default.GetCharCount(thebyte, 0, thebyte.Length)];   
      System.Text.Encoding.Default.GetChars(thebyte, 0, thebyte.Length, Chars, 0);   
      string newString = new string(Chars);   
      return newString;   
      }   
       
      //字符串转二进制:   
      private byte[] ConvertToByte(string theString)   
      {   
      byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);   
      return byteStream;   
      }