String.ToUpperInvariant メソッド

定義

インバリアント カルチャの大文字と小文字の規則を使用して、この String オブジェクトのコピーを大文字に変換して返します。

public:
 System::String ^ ToUpperInvariant();
public string ToUpperInvariant ();
member this.ToUpperInvariant : unit -> string
Public Function ToUpperInvariant () As String

戻り値

現在の文字列を大文字にしたもの。

次の例では、複数の言語で 1 つの単語を含む文字列配列を定義します。 メソッドは ToUpperInvariant 、各単語の大文字と小文字を区別しないバージョンを並列配列の要素に設定するために使用されます。 メソッドは Array.Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>) 、大文字の配列内の要素の順序に基づいて大文字と小文字を区別する配列を並べ替え、言語に関係なく要素が同じ順序で表示されるようにするために使用されます。

using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      string[] words = { "Tuesday", "Salı", "Вторник", "Mardi", 
                         "Τρίτη", "Martes", "יום שלישי", 
                         "الثلاثاء", "วันอังคาร" };
      StreamWriter sw = new StreamWriter(@".\output.txt");
            
      // Display array in unsorted order.
      foreach (string word in words)
         sw.WriteLine(word);

      sw.WriteLine();

      // Create parallel array of words by calling ToUpperInvariant.
      string[] upperWords = new string[words.Length];
      for (int ctr = words.GetLowerBound(0); ctr <= words.GetUpperBound(0); ctr++)
         upperWords[ctr] = words[ctr].ToUpperInvariant();
      
      // Sort the words array based on the order of upperWords.
      Array.Sort(upperWords, words, StringComparer.InvariantCulture);
      
      // Display the sorted array.
      foreach (string word in words)
         sw.WriteLine(word);

      sw.Close();      
   }
}
// The example produces the following output:
//       Tuesday
//       Salı
//       Вторник
//       Mardi
//       Τρίτη
//       Martes
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
//       
//       Mardi
//       Martes
//       Salı
//       Tuesday
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
open System
open System.IO

do
    let words = 
        [| "Tuesday"; "Salı"; "Вторник"; "Mardi" 
           "Τρίτη"; "Martes"; "יום שלישי" 
           "الثلاثاء"; "วันอังคาร" |]
    use sw = new StreamWriter(@".\output.txt")
        
    // Display array in unsorted order.
    for word in words do
        sw.WriteLine word

    sw.WriteLine()

    // Create parallel array of words by calling ToUpperInvariant.
    let upperWords = words |> Array.map (fun x -> x.ToUpperInvariant())
    
    // Sort the words array based on the order of upperWords.
    Array.Sort(upperWords, words, StringComparer.InvariantCulture)
    
    // Display the sorted array.
    for word in words do
        sw.WriteLine word
    sw.Close()      
// The example produces the following output:
//       Tuesday
//       Salı
//       Вторник
//       Mardi
//       Τρίτη
//       Martes
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
//       
//       Mardi
//       Martes
//       Salı
//       Tuesday
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
Imports System.IO

Module Example
   Public Sub Main()
      Dim words() As String = { "Tuesday", "Salı", "Вторник", "Mardi", _
                                "Τρίτη", "Martes", "יום שלישי", _
                                "الثلاثاء", "วันอังคาร" }
      Dim sw As New StreamWriter(".\output.txt")
      
      ' Display array in unsorted order.
      For Each word As String In words
         sw.WriteLine(word)
      Next
      sw.WriteLine()

      ' Create parallel array of words by calling ToUpperInvariant.
      Dim upperWords(words.Length - 1) As String
      For ctr As Integer = words.GetLowerBound(0) To words.GetUpperBound(0)
         upperWords(ctr) = words(ctr).ToUpperInvariant()
      Next
      
      ' Sort the words array based on the order of upperWords.
      Array.Sort(upperWords, words, StringComparer.InvariantCulture)
      
      ' Display the sorted array.
      For Each word As String In words
         sw.WriteLine(word)
      Next
      
      sw.Close()
   End Sub
End Module
' The example produces the following output:
'       Tuesday
'       Salı
'       Вторник
'       Mardi
'       Τρίτη
'       Martes
'       יום שלישי
'       الثلاثاء
'       วันอังคาร
'       
'       Mardi
'       Martes
'       Salı
'       Tuesday
'       Τρίτη
'       Вторник
'       יום שלישי
'       الثلاثاء
'       วันอังคาร

注釈

インバリアント カルチャは、カルチャに依存しないカルチャを表します。 これは英語に関連付けられていますが、特定の国や地域には関連付けされません。 詳細については、CultureInfo.InvariantCulture プロパティを参照してください。

アプリケーションが、現在のカルチャの影響を受けない予測可能な方法で文字列が変化する場合に依存する場合は、 メソッドを使用します ToUpperInvariant 。 メソッドは ToUpperInvariantToUpper(CultureInfo.InvariantCulture)同じです。 このメソッドは、文字列のコレクションがユーザー インターフェイス コントロールで予測可能な順序で表示される必要がある場合に推奨されます。

注意

このメソッドは、現在のインスタンスの値を変更しません。 代わりに、現在のインスタンス内のすべての文字が大文字に変換される新しい文字列を返します。

ファイル名、名前付きパイプ、レジストリ キーなど、オペレーティング システム識別子の小文字または大文字のバージョンが必要な場合は、 メソッドまたは ToUpperInvariant メソッドをToLowerInvariant使用します。

適用対象

こちらもご覧ください