Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.ToLower Method (CultureInfo)

Returns a copy of this String converted to lowercase, using the casing rules of the specified culture.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public string ToLower (
	CultureInfo culture
)
public String ToLower (
	CultureInfo culture
)
public function ToLower (
	culture : CultureInfo
) : String
Not applicable.

Parameters

culture

A CultureInfo object that supplies culture-specific casing rules.

Return Value

A String in lowercase.

Exception typeCondition

ArgumentNullException

culture is a null reference (Nothing in Visual Basic).

The casing rules of the culture that is currently in effect determines the way the case of a string is changed. If your application depends on the case of a string changing in a predictable way, and the effective culture changes unexpectedly, then you can get invalid results. Consider the following lookup routine where the lookup key is a text string, the key is forced to a standard case to simplify comparisons, and the effective culture is the culture associated with the current thread.

static object LookupKey(string key) { return internalHashtable[key.ToLower()]; }

If it is possible for the current thread and its associated culture to change unexpectedly, it is advisable to specify the invariant culture instead of defaulting to the current thread culture. The following example demonstrates the preferred technique.

static object LookupKey(string key) { return internalHashtable[key.ToLower(CultureInfo.InvariantCulture)]; }

Security Considerations

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.

The following code example converts two strings of uppercase characters to lowercase characters using the English-United States and Turkish-Turkey cultures, then compares the lowercase strings. The uppercase strings are identical except that for each occurrence of the Unicode LATIN CAPITAL LETTER I in one string, the other string contains LATIN CAPITAL LETTER I WITH DOT ABOVE.

// Sample for String.ToLower(CultureInfo)

using System;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
    String str1 = "INDIGO";
    // str2 = str1, except each 'I' is '\u0130' (Unicode LATIN CAPITAL I WITH DOT ABOVE).
    String str2 = new String(new Char[] {'\u0130', 'N', 'D', '\u0130', 'G', 'O'});
    String str3, str4;

    Console.WriteLine();
    Console.WriteLine("str1 = '{0}'", str1);

    Console.WriteLine();
    Console.WriteLine("str1 is {0} to str2.", 
         ((0 == String.CompareOrdinal(str1, str2)) ? "equal" : "not equal"));
    CodePoints("str1", str1);
    CodePoints("str2", str2);

    Console.WriteLine();
    // str3 is a lower case copy of str2, using English-United States culture.
    Console.WriteLine("str3 = Lower case copy of str2 using English-United States culture.");
    str3 = str2.ToLower(new CultureInfo("en-US", false));

    // str4 is a lower case copy of str2, using Turkish-Turkey culture.
    Console.WriteLine("str4 = Lower case copy of str2 using Turkish-Turkey culture.");
    str4 = str2.ToLower(new CultureInfo("tr-TR", false));

    // Compare the code points in str3 and str4.
    Console.WriteLine();
    Console.WriteLine("str3 is {0} to str4.", 
         ((0 == String.CompareOrdinal(str3, str4)) ? "equal" : "not equal"));
    CodePoints("str3", str3);
    CodePoints("str4", str4);
    }

    public static void CodePoints(String title, String s)
    {
    Console.Write("{0}The code points in {1} are: {0}", Environment.NewLine, title);
    foreach (ushort u in s)
      Console.Write("{0:x4} ", u);
    Console.WriteLine();
    }
}
/*
This example produces the following results:

str1 = 'INDIGO'

str1 is not equal to str2.

The code points in str1 are:
0049 004e 0044 0049 0047 004f

The code points in str2 are:
0130 004e 0044 0130 0047 004f

str3 = Lower case copy of str2 using English-United States culture.
str4 = Lower case copy of str2 using Turkish-Turkey culture.

str3 is equal to str4.

The code points in str3 are:
0069 006e 0064 0069 0067 006f

The code points in str4 are:
0069 006e 0064 0069 0067 006f
*/

// Sample for String.ToLower(CultureInfo)
import System.*;
import System.Globalization.*;

class Sample
{
    public static void main(String[] args)
    {
        String str1 = "INDIGO";
        // str2 = str1, except each 'I' is '\u0130' 
        // (Unicode LATIN CAPITAL I WITH DOT ABOVE).
        String str2 = new String(new char[] { '\u0130', 'N', 'D', '\u0130', 
            'G', 'O' });
        String str3, str4;

        Console.WriteLine();
        Console.WriteLine("str1 = '{0}'", str1);

        Console.WriteLine();
        Console.WriteLine("str1 is {0} to str2.", 
            (0 == String.CompareOrdinal(str1, str2)) ? "equal" : "not equal");
        CodePoints("str1", str1);
        CodePoints("str2", str2);
        Console.WriteLine();

        // str3 is a lower case copy of str2, using English-United States 
        // culture.
        Console.WriteLine("str3 = Lower case copy of str2 using English-United "
            + "States culture.");
        str3 = str2.ToLower(new CultureInfo("en-US", false));

        // str4 is a lower case copy of str2, using Turkish-Turkey culture.
        Console.WriteLine("str4 = Lower case copy of str2 using Turkish-Turkey "
            + "culture.");
        str4 = str2.ToLower(new CultureInfo("tr-TR", false));

        // Compare the code points in str3 and str4.
        Console.WriteLine();
        Console.WriteLine("str3 is {0} to str4.", 
            (0 == String.CompareOrdinal(str3, str4)) ? "equal" : "not equal");
        CodePoints("str3", str3);
        CodePoints("str4", str4);
    } //main

    public static void CodePoints(String title, String s)
    {
        Console.Write("{0}The code points in {1} are: {0}", 
            Environment.get_NewLine(), title);
        for (int iCtr = 0; iCtr < s.get_Length(); iCtr++) {
            UInt16 u = (UInt16)s.charAt(iCtr);
            Console.Write("{0:x4} ", u);
        }
        Console.WriteLine();
    } //CodePoints
} //Sample
/*
This example produces the following results:

str1 = 'INDIGO'

str1 is not equal to str2.

The code points in str1 are:
0049 004e 0044 0049 0047 004f

The code points in str2 are:
0130 004e 0044 0130 0047 004f

str3 = Lower case copy of str2 using English-United States culture.
str4 = Lower case copy of str2 using Turkish-Turkey culture.

str3 is equal to str4.

The code points in str3 are:
0069 006e 0064 0069 0067 006f

The code points in str4 are:
0069 006e 0064 0069 0067 006f
*/

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft