共用方式為


String.ToLowerInvariant 方法

定義

回傳此物件的副本 String ,並使用不變培養的大小寫規則轉換為小寫。

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

傳回

這是目前字串的小寫等價物。

範例

以下範例定義了一個包含多個語言單字的字串陣列。 此 ToLowerInvariant 方法用於將每個字的大小寫不區分版本填充平行陣列的元素。 此 Array.Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>) 方法用於根據小寫陣列中元素的順序排序大小寫區分陣列,確保元素無論語言為何,都以相同順序出現。

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
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
open System

let words = 
    [| "Tuesday"; "Salı"; "Вторник"; "Mardi" 
       "Τρίτη"; "Martes"; "יום שלישי" 
       "الثلاثاء"; "วันอังคาร" |]
// Display array in unsorted order.
for word in words do
    printfn $"{word}"
printfn ""

// Create parallel array of words by calling ToLowerInvariant.
let lowerWords = 
    words |> Array.map (fun x -> x.ToLowerInvariant())

// Sort the words array based on the order of lowerWords.
Array.Sort(lowerWords, words, StringComparer.InvariantCulture)

// Display the sorted array.
for word in words do
    printfn $"{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
'       Τρίτη
'       Вторник
'       יום שלישי
'       الثلاثاء
'       วันอังคาร

備註

不變文化表示對文化差異不敏感。 它與英語相關聯,但不屬於特定國家或地區。 如需詳細資訊,請參閱 CultureInfo.InvariantCulture 屬性 (Property)。

如果你的應用依賴於字串以可預測的方式改變且不受當前文化影響的情況,請使用此 ToLowerInvariant 方法。 該 ToLowerInvariant 方法等價於 ToLower(CultureInfo.InvariantCulture)。 當一組字串必須以可預測的順序出現在使用者介面控制項時,建議使用此方法。

備註

此方法不會修改當前實例的值。 取而代之的是,它會回傳一個新字串,該字串中目前實例中的所有字元都被轉換成小寫。

如果你需要作業系統識別碼的大小寫版本,例如檔名、命名管道或登錄檔鍵,請使用 ToLowerInvariant or ToUpperInvariant 方法。

適用於

另請參閱