C# string ToLower - Convert string to lowercase

c# string tolower

While writing C# code some times we need a string to be converted to lowercase string, so that the uppercase letters of the string get converted to lowercase letters. This is useful when you need to compare the string with lowercase string. It is good practice to make comparing strings to be convert to uppercase or lowercase if we don’t know how input is coming. We will see how to convert all letters to small case in the string using ToLower function in C#.

C# code that shows how to use ToLower [C#]


using System;
class Program
{
 static void Main()
 {
  string str = "C# STRING LOWERCASE EXAMPLE";
  string upStr = str.ToLower();
  Console.WriteLine(upStr);
 }
}

Result
c# string lowercase example


The ToLower function or method converts all the uppercase characters in the string to lowercase characters, If string contains some lowercase letters or characters it ignores them. We will see how to compare two strings by using lowercase to the input string.

using System;

class Program
{
 static void Main()
 {
  string str = "C# STRING LOWERCASE";
  string upStr = str.ToLower();
  if("c# string lowercase” == upStr)
  Console.WriteLine("Strings are equal.");
 }
}


Result
Strings are equal.

0 Comments :

Post a Comment