C# UTF8Encoding GetChars(Byte[], Int32, Int32, Char[], Int32)
Description
UTF8Encoding GetChars(Byte[], Int32, Int32, Char[], Int32)
Decodes a sequence of bytes from the specified byte array into the
specified character array.
Syntax
UTF8Encoding.GetChars(Byte[], Int32, Int32, Char[], Int32)
has the following syntax.
public override int GetChars(
byte[] bytes,/*from w w w . j a va 2 s .co m*/
int byteIndex,
int byteCount,
char[] chars,
int charIndex
)
Parameters
UTF8Encoding.GetChars(Byte[], Int32, Int32, Char[], Int32)
has the following parameters.
bytes
- The byte array containing the sequence of bytes to decode.byteIndex
- The index of the first byte to decode.byteCount
- The number of bytes to decode.chars
- The character array to contain the resulting set of characters.charIndex
- The index at which to start writing the resulting set of characters.
Returns
UTF8Encoding.GetChars(Byte[], Int32, Int32, Char[], Int32)
method returns The actual number of characters written into chars.
Example
using System;/* ww w . j a v a 2 s . c o m*/
using System.Text;
class UTF8EncodingExample
{
public static void Main()
{
Char[] chars;
Byte[] bytes = new Byte[] {69, 120, 97, 109, 112, 108, 101
};
UTF8Encoding utf8 = new UTF8Encoding();
int charCount = utf8.GetCharCount(bytes, 2, 13);
chars = new Char[charCount];
int charsDecodedCount = utf8.GetChars(bytes, 2, 13, chars, 0);
Console.WriteLine( charsDecodedCount);
foreach (Char c in chars)
{
Console.Write("[{0}]", c);
}
}
}
The code above generates the following result.