C# ASCIIEncoding GetString(Byte[])

Description

ASCIIEncoding GetString(Byte[]) When overridden in a derived class, decodes all the bytes in the specified byte array into a string.

Syntax

ASCIIEncoding.GetString(Byte[]) has the following syntax.


public virtual string GetString(
  byte[] bytes
)

Parameters

ASCIIEncoding.GetString(Byte[]) has the following parameters.

  • bytes - The byte array containing the sequence of bytes to decode.

Returns

ASCIIEncoding.GetString(Byte[]) method returns A string that contains the results of decoding the specified sequence of bytes.

Example


using System;//from   w  ww .  ja v a  2s  . com
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);
   }
}




















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding