Export (0) Print
Expand All

Encoding.GetEncoding Method (String)

.NET Framework 1.1

Returns an Encoding for the specified name.

[Visual Basic]
Overloads Public Shared Function GetEncoding( _
   ByVal name As String _
) As Encoding
[C#]
public static Encoding GetEncoding(
 string name
);
[C++]
public: static Encoding* GetEncoding(
 String* name
);
[JScript]
public static function GetEncoding(
   name : String
) : Encoding;

Parameters

name
The name of an Encoding.

Return Value

The requested encoding.

Exceptions

Exception Type Condition
NotSupportedException name is not a valid code page name.

-or-

The code page indicated by name is not supported by the underlying platform.

Remarks

The GetEncoding method relies on the underlying platform to support most code pages. However, system support is supplied for the following cases: The default encoding, that is, the encoding specified in the regional settings for the computer executing this method; little-endian Unicode (UTF-16LE); big-endian Unicode (UTF-16BE); Windows operating system (windows-1252); UTF-7; UTF-8; ASCII, and GB18030 (Chinese Simplified).

Specify one of the names listed in the following table to obtain the system supported encoding with the corresponding code page.

code page name
1200 "UTF-16LE", "utf-16", "ucs-2", "unicode", or "ISO-10646-UCS-2"
1201 "UTF-16BE" or "unicodeFFFE"
1252 "windows-1252"
65000 "utf-7", "csUnicode11UTF7", "unicode-1-1-utf-7", "unicode-2-0-utf-7", "x-unicode-1-1-utf-7", or "x-unicode-2-0-utf-7"
65001 "utf-8", "unicode-1-1-utf-8", "unicode-2-0-utf-8", "x-unicode-1-1-utf-8", or "x-unicode-2-0-utf-8"
20127 "us-ascii", "us", "ascii", "ANSI_X3.4-1968", "ANSI_X3.4-1986", "cp367", "csASCII", "IBM367", "iso-ir-6", "ISO646-US", or "ISO_646.irv:1991"
54936 "GB18030"

A specific code page might not be supported by certain platforms. For example, the Japanese shift-jis code page (code page 932) might not be supported in the United States version of Windows 98. In that case, the GetEncoding method throws NotSupportedException when the following C# code is executed:

Encoding enc = Encoding.GetEncoding("shift-jis");

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Encoding Class | Encoding Members | System.Text Namespace | Encoding.GetEncoding Overload List

Show:
© 2014 Microsoft