How do I determine if character is in lower or upper case?

Category: System, viewed: 4K time(s).

Use System.Char IsLower() or IsUpper() static method to determine character case.

using System;

namespace Kodecsharp.Example.System
{
    public class LowUpperCase
    {
        public static void Main(string[] args)
        {
            string phrase = "The Quick Brown Fox Jumps Over The Lazy Dog";
            char[] chars = phrase.ToCharArray();

            for (int i = 0; i < chars.Length; i++)
            {
                char c = chars[i];
                if (Char.IsLetter(c))
                {
                    if (Char.IsLower(c))
                    {
                        Console.WriteLine(c + " is lowercase");
                    }
                    else if (Char.IsUpper(c))
                    {
                        Console.WriteLine(c + " is uppercase");
                    }
                }
            }

            Console.ReadLine();
        }
    }
}
Powered by Disqus