String.ToLowerInvariant 方法

定義

使用不因文化特性而異的大小寫規則,傳回轉換成小寫的這個 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.

適用於

另請參閱