March 2004
Intermediate to advanced
560 pages
26h 47m
English
The following example demonstrates using the System.Text.UTF8Encoding implementation of the System.Text.Decoder class to convert two byte arrays to a character array, where one character's bytes span multiple byte arrays. This demonstrates how to use a System.Text.Decoder in streaming-like situations.
using System;
using System.Text;
namespace Samples
{
public class DecoderSample
{
public static void Main()
{
byte[] b1 = { 0x41, 0x23, 0xe2 };
byte[] b2 = { 0x98, 0xa3 };
Decoder d = Encoding.UTF8.GetDecoder();
char[] chars = new char[3];
int i = d.GetChars(b1, 0, b1.Length, chars, 0);
i += d.GetChars(b2, 0, b2.Length, chars, i);
foreach(char c in chars)
Console.Write("U+{0:x} ", (ushort)c);
}
}
}
U+41 U+23 U+2623
Read now
Unlock full access