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
|
No responses found. Be the first to respond and make money from revenue sharing program.
|