C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Case insensitive string comparisons


Posted Date: 23 Apr 2007    Resource Type: Code Snippets    Category: String Manipulations

Posted By: Sidhartha Gundavarapu       Member Level: Gold
Rating:     Points: 10



This snippet provides different ways to compare case insensitive strings. If you want to do a culture specific comparision, you can use the current culture instead of invariant culture.

Equal method returns boolean
Compare method returns int. 0 if equal


string str = "Test";
string str1 = "test";

//approach 1 - based on value
string.Equals( str, str1, StringComparison.InvariantCultureIgnoreCase );

//approach 2 - based on value
str.Equals( str1, StringComparison.InvariantCultureIgnoreCase );

//approach 3 - based of weights
string.Compare( str, str1, true );

//approach 4 - based on weights
string.Compare( str, str1, StringComparison.InvariantCultureIgnoreCase );

//approach 5 - based on weights
str.CompareTo( str1 ); //returns 1 -> left side has more weight than the right side
str1.CompareTo( str ); // returns -1 -> left side has less weight than left side
str1.CompareTo( str1 ); //returns 0 -> both are equal





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Proper case validation
Previous Resource: Validate the user input using StringValidator Class
Return to Discussion Resource Index
Post New Resource
Category: String Manipulations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

teleconferencing service

Contact Us    Privacy Policy    Terms Of Use