Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter the string : techstudy

After conversion, the string is: TECHSTUDY

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C# program to check whether a given substr... >>
<< Write a C# program to check the username and passw...