Tech Study

Write a C# program to read a sentence and replace lowercase characters by uppercase and vice-versa

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
public class Stringexercise
{
    public static void Main()
    {
        string str1;
        char[] arr1;
        int length, i;
        length = 0;
        char ch;        
        Console.Write("Enter the string : ");
        str1 = Console.ReadLine();
        length = str1.Length;
        arr1 = str1.ToCharArray(0, length); // Converts string into char array.
 
        Console.Write("\nAfter conversion, the string is: ");
        for (i = 0; i < length; i++)
        {
            ch = arr1[i];
            if (Char.IsLower(ch)) // check whether the character is lowercase
                Console.Write(Char.ToUpper(ch)); // Converts lowercase character to uppercase.
            else
                Console.Write(Char.ToLower(ch)); // Converts uppercase character to lowercase.
        }
        Console.ReadLine();
    }
}

Result

Write a C# program to read a sentence and replace lowercase characters by uppercase and vice-versa
Write a C# program to read a sentence and replace lowercase characters by uppercase and vice-versa

TaggedWrite a C# program to read a sentence and replace lowercase characters by uppercase and vice-versa

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more