Advertisement
Methods | Description |
---|---|
ToUpper() | This method returns an uppercase copy of the invoked String object. |
ToUpper(CultureInfo) | This method returns an uppercase copy of the invoked String object, by using the casing rule of the specified culture, specified by CultureInfo class. |
//Program to convert a String to uppercase letters.
using System;
class StringUpper
{
public static void Main()
{
//Creating the first String object
String str1 = "new zealand";
//Creating a char array
char[] charr = {'H', 'e', 'l', 'l', 'o'};
//Creating the second String object from a char[] array.
String str2 = new String(charr);
Console.WriteLine("First String is : "+ str1);
Console.WriteLine("First String's uppercase value : " + str1.ToUpper());
Console.WriteLine("Second String is : "+ str2);
Console.WriteLine("Second String's uppercase value : " + str2.ToUpper());
}
}
First String is : new zealand
First String's uppercase value : NEW ZEALAND
Second String is : Hello
Second String's uppercase value : HELLO
//C# Calling method ToUpper() does not modify the original content of the invoked String object
using System;
class StringUpper
{
public static void Main()
{
//Creating a String object
String str1 = "mars - the red planet";
//Creating a char array
char[] arr = {'E', 'a', 'r', 't', 'h'};
//Creating the second String object from a char[] array.
String str2 = new String(arr);
//Printing the value of the first String before calling ToUpper() on it
Console.WriteLine("First string : "+ str1);
//Printing the uppercase copy of the first String returned by ToUpper()
Console.WriteLine("First String's uppercase value : " + str1.ToUpper());
//Printing the value of the first String after calling ToUpper() on it.
Console.WriteLine("First string after calling ToUpper() : " + str1);
//Printing the value of the second String before calling ToUpper() on it
Console.WriteLine("Second string : "+ str2);
//Printing the uppercase copy of the second String returned by ToUpper()
Console.WriteLine("Second String's uppercase value : " + str2.ToUpper());
//Printing the value of the second String after calling ToUpper() on it.
Console.WriteLine("Second string after calling ToUpper() : " + str2);
}
}
First string : mars - the red planet
First String's uppercase value : MARS - THE RED PLANET
First string after calling ToUpper() : mars - the red planet
Second string : Earth
Second String's uppercase value : EARTH
Second string after calling ToUpper() : Earth
Advertisement
//C# Calling method ToUpper() does not modify the original content of the invoked String object
using System;
using System.Globalization;
class StringUpper
{
public static void Main()
{
//Creating a String object
String str1 = "Stay Amazing!";
//Printing the value of the first String before calling ToUpper() on it
Console.WriteLine("First string : "+ str1);
//Creating an object of CultureInfo class based on the English-US culture
CultureInfo ci1 = new CultureInfo("en-us", false);
//Creating an object of CultureInfo class based on the Turkish-Turkey culture
CultureInfo ci2 = new CultureInfo("tk-TR", false);
//Creating an object of CultureInfo class based on the Turkish-Turkey culture
CultureInfo ci3 = new CultureInfo("fr-FR", false);
//Printing an uppercase copy of the first String according to English-United States culture
Console.WriteLine("First String's uppercase value based on English-US culture: " + str1.ToUpper(ci1));
//Printing an uppercase copy of the first String according to Turkish-Turkey culture
Console.WriteLine("First String's uppercase value based on Turkish-Turkish culture: " + str1.ToUpper(ci2));
//Printing an uppercase copy of the first String according to French-France culture
Console.WriteLine("First String's uppercase value based on French-France culture: " + str1.ToUpper(ci3));
//Extracting the current culture of our system
CultureInfo current = CultureInfo.CurrentUICulture;
Console.WriteLine("The current UI culture of our system is {0}", current.Name);
}
}
First string : Stay Amazing!
First String's uppercase value based on English-US culture: STAY AMAZING!
First String's uppercase value based on Turkish-Turkish culture: STAY AMAZING!
First String's uppercase value based on French-France culture: STAY AMAZING!
The current UI culture is en-US
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement