asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Base Types > Basic String Operations > Changing Case

Changing Case

Getting Started   ASP.NET Base Types   Basic String Operations


If you write an application that accepts input from a user, you can never be sure what case he or she will use to enter the data. Because the methods that compare strings and characters are case-sensitive, you should convert the case of strings entered by users before comparing them to constant values. You can easily change the case of a string. The following table describes the two available case-changing methods.

Method Name Use
String.ToUpper Converts all characters in a string to uppercase.
String.ToLower Converts all characters in a string to lowercase.

Each method provides an override that accepts a culture.

ToUpper

The String.ToUpper method changes all characters in a string to uppercase. The following code example converts the string "Hello World!" from mixed case to uppercase.

 [ VB ]
Dim myString As String = "Hello World!"
Console.WriteLine ( myString.ToUpper ( ) )
 [ C# ]
String myString = "Hello World!";
Console.WriteLine ( myString.ToUpper ( ) );

This example displays HELLO WORLD!to the console.

ToLower

The String.ToLowermethod is similar to the previous method, but instead converts all the characters in a string to lowercase. The following code example converts the string "HELLO WORLD!" to lowercase.

 [ VB ]
Dim myString As String = "Hello World!"
Console.WriteLine ( myString.ToLower ( ) )
 [ C# ]
String myString = "Hello World!";
Console.WriteLine ( myString.ToLower ( ) );

This example displays hello world! to the console.

See Also

Basic String Operations



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note