708
In this example we will create a program to change a user inputted string to lowercase.
For this we use the String.ToLower() Method which as the name suggests will return an lowercase 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 ToLower();
Example
In this example we ask the user to input a string and we will convert it to upper case using the String.ToLower() 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.ToLower(); //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 a couple of test runs
Enter string : ALL CAPS TEXT The Converted upper case string is: all caps text Press any key to exit. Enter string : MixED cASE examPLE The Converted upper case string is: mixed case example Press any key to exit.
As expected the text display is in lowercase
Note
There is also a ToLower(CultureInfo) method
This returns a copy of this string converted to lowercase, using the casing rules of the specified culture.