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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. public class Stringexercise
  3. {
  4. public static void Main()
  5. {
  6. string str1;
  7. char[] arr1;
  8. int length, i;
  9. length = 0;
  10. char ch;
  11. Console.Write("Enter the string : ");
  12. str1 = Console.ReadLine();
  13. length = str1.Length;
  14. arr1 = str1.ToCharArray(0, length); // Converts string into char array.
  15.  
  16. Console.Write("\nAfter conversion, the string is: ");
  17. for (i = 0; i < length; i++)
  18. {
  19. ch = arr1[i];
  20. if (Char.IsLower(ch)) // check whether the character is lowercase
  21. Console.Write(Char.ToUpper(ch)); // Converts lowercase character to uppercase.
  22. else
  23. Console.Write(Char.ToLower(ch)); // Converts uppercase character to lowercase.
  24. }
  25. Console.ReadLine();
  26. }
  27. }

Result

C# language techstudy

     





Related Topics




Popular Posts