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