C# UnicodeEncoding GetString(Byte[], Int32, Int32)

Description

UnicodeEncoding GetString(Byte[], Int32, Int32) Decodes a range of bytes from a byte array into a string.

Syntax

UnicodeEncoding.GetString(Byte[], Int32, Int32) has the following syntax.


[ComVisibleAttribute(false)]/* w w  w. j  a v a 2 s.  com*/
public override string GetString(
  byte[] bytes,
  int index,
  int count
)

Parameters

UnicodeEncoding.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

UnicodeEncoding.GetString(Byte[], Int32, Int32) method returns A String object containing the results of decoding the specified sequence of bytes.

Example


using System;/*from  w  ww.j  av  a  2 s .  c  o m*/
using System.Text;

public class SamplesUnicodeEncoding
{

    public static void Main()
    {
        UnicodeEncoding u16LE = new UnicodeEncoding(false, true, true);
        UnicodeEncoding enc = new UnicodeEncoding(true, true, true);

        String myStr = "za\u0306\u01FD\u03B2";
        byte[] barrBE = new byte[enc.GetByteCount(myStr)];
        enc.GetBytes(myStr, 0, myStr.Length, barrBE, 0);
        byte[] barrLE = new byte[u16LE.GetByteCount(myStr)];
        u16LE.GetBytes(myStr, 0, myStr.Length, barrLE, 0);

        Console.Write("{0,-25} :", enc.ToString());
        Console.WriteLine(enc.GetString(barrBE, 0, barrBE.Length));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding