NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

StreamReader.SwitchEncoding (Encoding, Int32)

Switches the current stream's encoding to the new one, reading from the specified character position onward.

[Visual Basic]
Overloads Overridable Public Sub SwitchEncoding( _
   ByVal enc As Encoding, _
   ByVal useCharPos As Integer _
)
[C#]
public virtual void SwitchEncoding(
   Encoding enc,
   int useCharPos
);
[C++]
public: virtual void SwitchEncoding(
   Encoding* enc,
   int useCharPos
);
[JScript]
public function SwitchEncoding(
   enc : Encoding,
   useCharPos : int
);

Parameters

enc
The new encoding to use.
useCharPos
The position at which you want to start using the new encoding.

Exceptions

Exception Type Condition
ArgumentException useCharPos is invalid.
ArgumentNullException enc is a null reference (in Visual Basic Nothing).
InvalidOperationException SwitchEncoding is called after reading past the first character buffer's worth of data.

Remarks

SwitchEncoding supports the reading of a few lines of header information in one encoding, and then reading the rest of the document in a different encoding.

SwitchEncoding cannot be called after you have read past the first character buffer's worth of data.

This method re-encodes from the specified character position in the stream onwards. Once a stream encoding has been changed, there is no way to read the previous characters from the StreamReader. The bytes are lost.

Note   This will only succeed if the StreamReader has not read more than one buffer's worth of data. You can control this to an extent with the bufferSize parameter to the StreamReader constructor.

See Also

StreamReader Class | StreamReader Members | System.IO Namespace | StreamReader.SwitchEncoding Overload List