Encoder.Convert Method (Char*, Int32, Byte*, Int32, Boolean, Int32, Int32, Boolean)

Converts a buffer of Unicode characters to an encoded byte sequence and stores the result in another buffer.

This method is not CLS-compliant.   The CLS-compliant alternative is Convert(Char[],Int32,Int32,Byte[],Int32,Int32,Boolean,Int32,Int32,Boolean).

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

[ComVisibleAttribute(false)] 
[CLSCompliantAttribute(false)] 
public virtual void Convert (
	char* chars,
	int charCount,
	byte* bytes,
	int byteCount,
	bool flush,
	out int charsUsed,
	out int bytesUsed,
	out bool completed
)
Not applicable.

Parameters

chars

The address of a string of UTF-16 encoded characters to convert.

charCount

The number of characters in chars to convert.

bytes

The address of a buffer to store the converted bytes.

byteCount

The maximum number of bytes in bytes to use in the conversion.

flush

true to indicate no further data is to be converted; otherwise, false.

charsUsed

When this method returns, contains the number of characters from chars that were used in the conversion. This parameter is passed uninitialized.

bytesUsed

When this method returns, contains the number of bytes that were used in the conversion. This parameter is passed uninitialized.

completed

When this method returns, contains true if all the characters specified by charCount were converted; otherwise, false. This parameter is passed uninitialized.

Exception typeCondition

ArgumentNullException

chars or bytes is a null reference (Nothing in Visual Basic)(Nothing).

ArgumentOutOfRangeException

charCount or byteCount is less than zero.

ArgumentException

The output buffer is too small to contain any of the converted input. The output buffer should be greater than or equal to the size indicated by the GetByteCount method.

EncoderFallbackException

A fallback occurred (see Understanding Encodings for fuller explanation)

-and-

Fallback is set to EncoderExceptionFallback.

Remember that the Encoder object saves state between calls to Convert. When the application is done with a stream of data, it should set the flush parameter to true to make sure that the state information is flushed. With this setting, the encoder ignores invalid bytes at the end of the data block and clears the internal buffer. Any remaining processed data that is part of a logical unit, such as the high surrogate of a surrogate pair, is converted according to the current fallback settings.

The Convert method is designed to be used in a loop to encode an arbitrary amount of input, such as data read from a file or stream. It stores the output of the encoding operation in a fixed-size buffer.

The completed output parameter indicates whether all the data in the input buffer was converted and stored in the output buffer. This parameter is set to false if the number of characters specified by the charCount parameter cannot be converted without exceeding the number of bytes specified by the byteCount parameter. In that situation, the application should use the contents of the output buffer or provide a new output buffer, increment the chars parameter by the number of characters specified by the charsUsed parameter, then call the Convert method again to process the remaining input.

The completed parameter can also be set to false, even though the charsUsed and charCount parameters are equal. This situation occurs if there is still data in the Encoder object that has not been stored in the chars buffer.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show: