December 2007
Intermediate to advanced
896 pages
19h 57m
English
Many methods in the FCL return a byte[] because they are providing a byte stream service, but some applications need to pass strings over these byte stream services. Some of these methods include:
System.Diagnostics.EventLogEntry.Data System.IO.BinaryReader.Read System.IO.BinaryReader.ReadBytes System.IO.FileStream.Read System.IO.FileStream.BeginRead System.IO.MemoryStream // Constructor System.IO.MemoryStream.Read System.IO.MemoryStream.BeginRead System.Net.Sockets.Socket.Receive System.Net.Sockets.Socket.ReceiveFrom System.Net.Sockets.Socket.BeginReceive System.Net.Sockets.Socket.BeginReceiveFrom System.Net.Sockets.NetworkStream.Read System.Net.Sockets.NetworkStream.BeginRead System.Security.Cryptography.CryptoStream.Read System.Security.Cryptography.CryptoStream.BeginRead
In many cases, this byte[] might contain ASCII-or Unicode-encoded characters. You need a way to recombine this byte[] to obtain the original string.
To convert a byte array of ASCII values to a complete string, use the following method:
string constructedString = Encoding.ASCII.GetString(characters);
To convert a byte array of Unicode values to a complete string, use the following method:
string constructedString = Encoding.Unicode.GetString(characters);
The GetString method of the Encoding class (returned by the ASCII property) converts 7-bit ASCII characters contained in a byte array to a string. Any value larger than 127 ...
Read now
Unlock full access