String.ToLowerInvariant String.ToLowerInvariant String.ToLowerInvariant String.ToLowerInvariant Method

定義

使用不因文化特性而異的大小寫規則,傳回轉換成小寫的這個 String 物件之複本。Returns a copy of this String object converted to lowercase using the casing rules of the invariant culture.

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

傳回

目前字串的小寫對應項。The lowercase equivalent of the current string.

範例

下列範例會定義包含有多種語言中的一個字的字串陣列。The following example defines a string array that contains a single word in a number of languages. ToLowerInvariant方法用來填入每個單字的不區分大小寫版本的平行陣列元素。The ToLowerInvariant method is used to populate the elements of a parallel array with the case-insensitive version of each word. Array.Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>)方法用來排序依據以確保項目,會出現在相同的順序,不論語言為何小寫的陣列中項目順序的區分大小寫陣列。The Array.Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>) method is used to sort the case-sensitive array based on the order of elements in the lowercase array to ensure that elements appear in the same order regardless of language.

using System;

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

      // Create parallel array of words by calling ToLowerInvariant.
      string[] lowerWords = new string[words.Length];
      for (int ctr = words.GetLowerBound(0); ctr <= words.GetUpperBound(0); ctr++)
         lowerWords[ctr] = words[ctr].ToLowerInvariant();
      
      // Sort the words array based on the order of lowerWords.
      Array.Sort(lowerWords, words, StringComparer.InvariantCulture);
      
      // Display the sorted array.
      foreach (string word in words)
         Console.WriteLine(word);
   }
}
// The example displays the following output:
//       Tuesday
//       Salı
//       Вторник
//       Mardi
//       Τρίτη
//       Martes
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
//       
//       Mardi
//       Martes
//       Salı
//       Tuesday
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
Module Example
   Public Sub Main()
      Dim words() As String = { "Tuesday", "Salı", "Вторник", "Mardi", _
                                "Τρίτη", "Martes", "יום שלישי", _
                                "الثلاثاء", "วันอังคาร" }
      ' Display array in unsorted order.
      For Each word As String In words
         Console.WriteLine(word)
      Next
      Console.WriteLine()

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

備註

文化特性而異表示不區分文化特性的文化特性。The invariant culture represents a culture that is culture-insensitive. 相關聯的英文語言使用,但不是能搭配特定國家或地區。It is associated with the English language but not with a specific country or region. 如需詳細資訊,請參閱 CultureInfo.InvariantCulture 屬性 (Property)。For more information, see the CultureInfo.InvariantCulture property.

如果您的應用程式相依於大小寫的字串,變更不會受到目前文化特性使用的可預測方式ToLowerInvariant方法。If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the ToLowerInvariant method. ToLowerInvariant方法就相當於ToLower(CultureInfo.InvariantCulture)The ToLowerInvariant method is equivalent to ToLower(CultureInfo.InvariantCulture). 字串集合必須出現在使用者介面控制項中可預測的順序時,建議的方法。The method is recommended when a collection of strings must appear in a predictable order in a user interface control.

注意

這個方法不會修改目前的執行個體的值。This method does not modify the value of the current instance. 相反地,它會傳回目前的執行個體中的所有字元都轉換成小寫的新字串。Instead, it returns a new string in which all characters in the current instance are converted to lowercase.

安全性考量Security Considerations

如果您需要大寫或小寫版本的作業系統識別項,例如檔案名稱,具名管道或登錄機碼,使用ToLowerInvariantToUpperInvariant方法。If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the ToLowerInvariant or ToUpperInvariant methods.

適用於

另請參閱