« Home | Detecting Chrome browser in ASP.NET » | Chart Control for .net 3.5 » | Increase the VS screen for HTML pages » | Working with Dynamic Controls » | Dynamics CRM 4.O SDK for IPHONE » | Sql Injection Tracking Tool » | Using LogParser to get Download Details from IIS » | Getting IP Address and ISP name of our Web Page Vi... » | Error Handling in Web.Config » | Handling Application_Error Method »

String is All Lower or All Upper Case

How do we find a string is All Lower or All Upper case characters?

There are so many ways to accomplish the same thing. We immediately go to the most simple solution; using the ToLower() method on the string object and comparing the original string input to the lower version of the same sentence. The code is shown below.

private bool IsAllLowerCase(string value)
{
return (value.Equals(value.ToLower()));
}

This is a simple method that should be fairly performant. We can make it great performant by using a regular expression. This is shown in the following code:

using System.Text.RegularExpressions;

private bool IsAllLowerCase(string value)
{
// Allow anything but upper case
return new Regex(@"^([^A-Z])+$").IsMatch(value);
}

We can flip around the above regular expression to check for Upper Case.

Happy Coding...

Labels: , , , , , ,

Post a Comment