String.ToUpperInvariant Method
Assembly: mscorlib (in mscorlib.dll)
If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the ToUpperInvariant method. The ToUpperInvariant method is equivalent to ToUpper(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 a string of lowercase characters to two strings of uppercase characters using the English-United States and Turkish-Turkey cultures, then compares the uppercase 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.ToUpper(CultureInfo) using System; using System.Globalization; class Sample { public static void Main() { String str1 = "indigo"; String str2, str3; Console.WriteLine(); Console.WriteLine("str1 = '{0}'", str1); Console.WriteLine("str2 = Upper case copy of str1 using English-United States culture."); // str2 is an upper case copy of str1, using English-United States culture. str2 = str1.ToUpper(new CultureInfo("en-US", false)); // str3 is an upper case copy of str1, using Turkish-Turkey culture. Console.WriteLine("str3 = Upper case copy of str1 using Turkish-Turkey culture."); str3 = str1.ToUpper(new CultureInfo("tr-TR", false)); // Compare the code points in str2 and str3. Console.WriteLine(); Console.WriteLine("str2 is {0} to str3.", ((0 == String.CompareOrdinal(str2, str3)) ? "equal" : "not equal")); CodePoints("str1", str1); CodePoints("str2", str2); CodePoints("str3", str3); } 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' str2 = Upper case copy of str1 using English-United States culture. str3 = Upper case copy of str1 using Turkish-Turkey culture. str2 is not equal to str3. The code points in str1 are: 0069 006e 0064 0069 0067 006f The code points in str2 are: 0049 004e 0044 0049 0047 004f The code points in str3 are: 0130 004e 0044 0130 0047 004f */
// Sample for String.ToUpper(CultureInfo)
import System.*;
import System.Globalization.*;
class Sample
{
public static void main(String[] args)
{
String str1 = "indigo";
String str2, str3;
Console.WriteLine();
Console.WriteLine("str1 = '{0}'", str1);
Console.WriteLine("str2 = Upper case copy of str1 using English-"
+ "United States culture.");
// str2 is an upper case copy of str1, using English-United States
// culture.
str2 = str1.ToUpper(new CultureInfo("en-US", false));
// str3 is an upper case copy of str1, using Turkish-Turkey culture.
Console.WriteLine("str3 = Upper case copy of str1 using Turkish-"
+ "Turkey culture.");
str3 = str1.ToUpper(new CultureInfo("tr-TR", false));
// Compare the code points in str2 and str3.
Console.WriteLine();
Console.WriteLine("str2 is {0} to str3.",
(0 == String.CompareOrdinal(str2, str3)) ? "equal" : "not equal");
CodePoints("str1", str1);
CodePoints("str2", str2);
CodePoints("str3", str3);
} //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'
str2 = Upper case copy of str1 using English-United States culture.
str3 = Upper case copy of str1 using Turkish-Turkey culture.
str2 is not equal to str3.
The code points in str1 are:
0069 006e 0064 0069 0067 006f
The code points in str2 are:
0049 004e 0044 0049 0047 004f
The code points in str3 are:
0130 004e 0044 0130 0047 004f
*/
Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.