Checks whether a word or sentence is capitalized - CSharp System

CSharp examples for System:String Case

Description

Checks whether a word or sentence is capitalized

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*from w  ww . j  a va  2s  .c  o m*/

public class Main{
        //Checks whether a word or sentence is capitalized
        //Word -> True
        //OR
        //This is a sentence -> True
        public static bool IsCapitalized(string input)
        {
            if (input.Length == 0) return false;
            return String.CompareOrdinal(input.Substring(0, 1), input.Substring(0, 1).ToUpper()) == 0;
        }
}

Related Tutorials