C# UTF8Encoding GetString(Byte[])
Description
UTF8Encoding GetString(Byte[])
When overridden in
a derived class, decodes all the bytes in the specified byte array into a string.
Syntax
UTF8Encoding.GetString(Byte[])
has the following syntax.
public virtual string GetString(
byte[] bytes
)
Parameters
UTF8Encoding.GetString(Byte[])
has the following parameters.
bytes
- The byte array containing the sequence of bytes to decode.
Returns
UTF8Encoding.GetString(Byte[])
method returns A string that contains the results of decoding the specified sequence of
bytes.
Example
using System;//from w ww. ja va2 s. c o m
using System.IO;
using System.Text;
public class Example
{
const int MAX_BUFFER_SIZE = 2048;
static Encoding enc8 = Encoding.UTF8;
public static void Main()
{
FileStream fStream = new FileStream(@".\Utf8Example.txt", FileMode.Open);
string contents = null;
Byte[] bytes = new Byte[fStream.Length];
fStream.Read(bytes, 0, bytes.Length);
contents = enc8.GetString(bytes);
fStream.Close();
Console.WriteLine(contents);
}
}
The code above generates the following result.