次の方法で共有


Encoding.GetEncoding メソッド (String)

指定した名前の Encoding を返します。

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

パラメータ

戻り値

要求されたエンコーディング。

例外

例外の種類 条件
NotSupportedException name が有効なコード ページ名ではありません。

または

name が示すコード ページは基になるプラットフォームでサポートされていません。

解説

GetEncoding メソッドは、多くのコード ページをサポートしている、基になるプラットフォームに依存します。ただし、次の場合には、システム サポートが提供されます。このメソッドを実行しているコンピュータの地域設定で指定されたエンコーディングである既定のエンコーディング、リトル エンディアン Unicode (UTF-16LE)、ビッグ エンディアン Unicode (UTF-16BE)、Windows オペレーティング システム (Windows-1252)、UTF-7、UTF-8、ASCII、および GB18030 (Chinese Simplified) に対してシステム サポートが提供されます。

対応するコード ページで、システムによってサポートされるエンコーディングを取得するには、次の表で示された名前のいずれかを指定します。

コード ページ 名前
1200 "UTF-16LE"、"utf-16"、"ucs-2"、"unicode"、または "ISO-10646-UCS-2"
1201 "UTF-16BE" または "unicodeFFFE"
1252 "Windows-1252"
65000 "utf-7"、"csUnicode11UTF7"、"unicode-1-1-utf-7"、"unicode-2-0-utf-7"、"x-unicode-1-1-utf-7"、または "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"、または "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"、または "ISO_646.irv:1991"
54936 "GB18030"

プラットフォームによっては、特定のコード ページがサポートされていない場合があります。たとえば、日本の shift-jis コード ページ (コード ページ 932) は、Windows 98 の米国版ではサポートされていない場合があります。この場合、次に示す C# コードが実行されると、 GetEncoding メソッドは NotSupportedException をスローします。

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

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Encoding クラス | Encoding メンバ | System.Text 名前空間 | Encoding.GetEncoding オーバーロードの一覧