Byte array <=> String in C# .Net

Byte myBytes1[]   =   myMemoryStream.ToArray();
String str   =   System.Text.Encoding.Default.GetString( myBytes1  );
Byte myBytes2[]=System.Text.Encoding.Default.GetBytes( str )   ;

Byte   myBytes1[]   =   myMemoryStream.ToArray   ();
String   str   =   (new   UnicodeEncoding()).GetString( myBytes1 );
Byte   myBytes2[]   =   (new   UnicodeEncoding()).GetBytes( str )   ;

3 thoughts on “Byte array <=> String in C# .Net”

  1. 对于从Byte Stream到Char Stream的转换,有一个专门的类 StreamReader
    TextReader reader = new StreamReader(myMemoryStream, Encoding.Default);
    //从reader里面读字符串

    对于很大的ByteStream 这个方法最节省空间。

Leave a Reply

Your email address will not be published. Required fields are marked *