627
In this example we will create a program to change a user inputted string to upper case.
For this we use the String.ToUpper() Method which as the name suggests will return an uppercase converted string.
It should be noted that if the string contains a character that does not have an uppercase equivalent, it will remain unchanged. An example of these are special symbols.
Syntax:
public string ToUpper();
Example
In this example we ask the user to input a string and we will convert it to upper case using the String.ToUpper() Method
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { String myString1; String myString2; //prompt user to enter string Console.Write("Enter string : "); //store string as myString1 myString1 = Console.ReadLine(); //convert to upper case myString2 = myString1.ToUpper(); //display the user entered string in upper case Console.WriteLine("The Converted upper case string is: " + myString2); Console.WriteLine("Press any key to exit."); Console.ReadLine(); } } }
Here we show two runs
The Converted upper case string is: THIS IS A TEST STRING Press any key to exit. Enter string : ThIs IS a test STRing The Converted upper case string is: THIS IS A TEST STRING Press any key to exit.
As expected the text display is in upper case
Note
There is also a ToUpper(CultureInfo) method
This returns a copy of this string converted to uppercase, using the casing rules of the specified culture.