Επεξεργασία

Κοινή χρήση μέσω


String.ToLowerInvariant Method

Definition

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

Returns

The lowercase equivalent of the current string.

Examples

The following example defines a string array that contains a single word in a number of languages. The ToLowerInvariant method is used to populate the elements of a parallel array with the case-insensitive version of each word. 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
//       Τρίτη
//       Вторник
//       יום שלישי
//       الثلاثاء
//       วันอังคาร
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
'       Τρίτη
'       Вторник
'       יום שלישי
'       الثلاثاء
'       วันอังคาร

Remarks

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. For more information, see the CultureInfo.InvariantCulture property.

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. 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.

Note

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.

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.

Applies to

See also