Share via


別のカルチャの書式

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

ほとんどのメソッド、文字列書式指定子のいずれかを使用して返される値が、現在のカルチャまたは指定したカルチャに基づいて動的に変更する機能をあります。 たとえば、 の ToString メソッドのオーバーロードは、 IFormatProvider インターフェイスを実装する書式プロバイダを受け入れます。 このインターフェイスを実装するクラスは、小数点と桁区切り記号およびスペル チェックと通貨記号の配置して使用する文字を指定できます。 このパラメータを受け取るオーバーライドを使用しない場合、 の ToString メソッドは、現在のカルチャで指定された文字を使用します。

次の使用例は、CultureInfo クラスを使用してを の ToString メソッドと書式指定文字列で使用されるカルチャ指定しませんします。 このコードは、と呼ばれる、 CultureInfo の MyCulture クラスの新しいインスタンスを作成し、それをフランス語カルチャ文字列 fr-FR を使用して初期化します。 このオブジェクトは、フランス語の金銭的価値を生成する 文字列書式指定子を持つの ToString C メソッドに渡されます。

                        Dim MyInt AsInteger = 100
Dim MyCulture AsNew CultureInfo("fr-FR")
Dim MyString AsString = MyInt.ToString("C", MyCulture)
Console.WriteLine(MyString)
                        int MyInt = 100;
CultureInfo MyCulture = new CultureInfo("fr-FR");
String MyString = MyInt.ToString("C", MyCulture);
Console.WriteLine(MyString);

上記 100,00 を Windows フォームのフォームで表示したとき表示します。 注意してください、コンソールの環境では、すべての Unicode 文字がサポートされていません代わりに 100,00 ? が表示されます。

すべてサポートされているカルチャの一覧については CultureInfo クラス参照してください。

次の例は、現在のスレッドに関連付けられている、CultureInfo オブジェクトを変更方法を示します。 この使用例を前提としていますが U. S. 版 英語 (en-US) は、現在のスレッドに関連付けられているカルチャ示し、そのコードによってカルチャを変更する方法説明します。 This example also demonstrates how to specify a particular culture by passing a modified CultureInfo to a ToStringmethod and how to pass a new DateTimeFormatInfo to a ToString method.

                        Dim dt As DateTime = DateTime.Now
Dim dfi As DateTimeFormatInfo = New DateTimeFormatInfo()
Dim ci As CultureInfo = New CultureInfo("de-DE")

' Create a new custom time pattern for demonstration.
dfi.MonthDayPattern = "MM-MMMM, ddd-dddd"
' Use the DateTimeFormat from the culture associated with ' the current thread.

Console.WriteLine( dt.ToString("d") ) 
Console.WriteLine( dt.ToString("m") )

' Use the DateTimeFormat object from the specific culture passed.
Console.WriteLine( dt.ToString("d", ci ) )

' Use the settings from the DateTimeFormatInfo object passed.
Console.WriteLine( dt.ToString("m", dfi ) )

' Reset the current thread to a different culture.
Thread.CurrentThread.CurrentCulture = New CultureInfo("fr-BE")
Console.WriteLine( dt.ToString("d") )
' This example produces the following output:'       3/27/2008'       March 27'       27.03.2008'       03-March, Thu-Thursday'       27/03/2008      
DateTime dt = DateTime.Now;
DateTimeFormatInfo dfi = new DateTimeFormatInfo();
CultureInfo ci = new CultureInfo("de-DE");

// Create a new custom time pattern for demonstration.
dfi.MonthDayPattern = "MM-MMMM, ddd-dddd";

// Use the DateTimeFormat from the culture associated with // the current thread.
Console.WriteLine( dt.ToString("d") ); 
Console.WriteLine( dt.ToString("m") );

// Use the DateTimeFormat object from the specific culture passed.
Console.WriteLine( dt.ToString("d", ci ) );

// Use the settings from the DateTimeFormatInfo object passed.
Console.WriteLine( dt.ToString("m", dfi ) );

// Reset the current thread to a different culture.
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-BE");
Console.WriteLine( dt.ToString("d") );
// This example produces the following output://       3/27/2008//       March 27//       27.03.2008//       03-March, Thu-Thursday//       27/03/2008

参照

参照

System.IFormatProvider

System.Globalization.CultureInfo

その他の技術情報

書式の種類