C# - Convert String to Uppercase

Given a string, we have to convert it to uppercase using C# program.
[Last updated : March 20, 2023]

To convert a given string to uppercase, we use String.ToUpper() method.

Example

1) Input String: "This is india" then it will convert into : "THIS IS INDIA".
2) Input String: "This Is India" then it will convert into : "THIS IS INDIA".
3) Input String: "this is india" then it will convert into : "THIS IS INDIA".
4) Input String: "tHIS iS iNDIA" then it will convert into : "THIS IS INDIA".

String.ToUpper()

The String.ToUpper() method returns uppercase converted string.

Syntax

String String.ToUpper();

C# program to convert string to uppercase

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
  class Program {
    static void Main() {
      String str1;
      String str2;

      Console.Write("Enter string : ");
      str1 = Console.ReadLine();

      str2 = str1.ToUpper();

      Console.WriteLine("Converted string is: " + str2);

    }
  }

}

Output

Enter string : This Is India
Converted string is: THIS IS INDIA

C# Basic Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.