TextEncodingConverterGetEncoding(Int32, Boolean) Method

Returns a corresponding Encoding object for the specified code page number.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static Encoding GetEncoding(
	int codePage,
	bool throwOnInvalidCodePage = false
)

Parameters

codePage  Int32

The code page number.

  Caution

0 is treated as an invalid argument. This behavior is different from that of the Encoding class.
throwOnInvalidCodePage  Boolean  (Optional)
Pass true to have the method throw an ArgumentException if codePage could not be converted.

Return Value

Encoding
An Encoding object that corresponds to the specified code page number. If no match is found, UTF8 is returned by default. If the method is called with true as an argument for the throwOnInvalidCodePage parameter, an ArgumentException will be thrown instead.

Remarks

.NET Standard and .NET 5.0 or later only recognize a small number of character sets by default. The method overrides this default.

The properties EncoderFallback and DecoderFallback of the generated Encoding object are set to ReplacementFallback.

Exceptions

ArgumentOutOfRangeExceptioncodePage is less than 1 or greater than 65535. This exception is only thrown if the optional parameter throwOnInvalidCodePage is true.
ArgumentExceptioncodePage could not be mapped to a Encoding object. This exception is only thrown if the optional parameter throwOnInvalidCodePage is true.

See Also