How to convert a string characters: upper to lower and lower to upper in C#

1 Answer

0 votes
using System;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "Convert a HARD DISK or partition TO NTFS format";
            StringBuilder sb = new StringBuilder(s);
            int i = 0;

            try
            {
                while (i < s.Length)
                {
                    if (Char.IsLower(s[i]))
                        sb[i] = Char.ToUpper(s[i]);
                    else if (Char.IsUpper(s[i]))
                             sb[i] = Char.ToLower(s[i]);
                    i++;
                }
                s = sb.ToString();
                Console.WriteLine(s);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }

}

/*
run:
   
cONVERT A hard disk OR PARTITION to ntfs FORMAT
 
*/


answered May 29, 2015 by avibootz
edited May 29, 2015 by avibootz
...