Case insensitive comparison on textbox value in C#

Posted on 2009-04-23
Last Modified: 2013-12-17
I am simply trying to run a comparison on the value entered into a textbox. I want the comparison to not care about the case in which the value was entered. ("OPEN" vs "open") So my comparison currently looks like this:
if (textbox1.text == 'open')
do this logic

How do I make it case insensitive ? I have read I can use String.Compare to do this. But I can't seem to find the correct syntax. Any help would be greatly appreciated.

Question by:jazzcatone
    LVL 10

    Accepted Solution

    Try this...

    if (System.String.Compare(textbox1.text,"open", true) == 0 )
    do this logic

    Open in new window

    LVL 10

    Expert Comment


    Expert Comment

    textBox1.Text.ToLower().Trim() == "open"

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now