How to Compare Two Strings by Ignoring Case in C# – Programming, Pseudocode Example, C# Programming Example
C# Windows Form

How to Compare Two Strings by Ignoring Case in C#

In this example, i’ll show you How to compare two strings by ignoring case in C# Windows Form Application.

we can compare two specified string objects using String.Compare method. String.Compare() method returns an integer that indicates their relative position in the sort order. this method is overloaded.

String.Compare(String, String, Boolean) method overload compare two specified string objects by ignoring or honoring their case. so we can use this overloaded method to compare two string objects by ignoring case (case insensitive string comparison).

this overloaded method require three parameters. First two parameters are two string objects those we need to compare. and third parameter is a Boolean value. we must set the Boolean parameter to True when we need to ignore case during comparison. or we must set the Boolean parameter to False to honor case during string comparison.

if the method returned integer is less than zero, then the first string (strA) is less than the second string (strB). if it return zero, then two specified strings are equals. and if the return value is greater than zero, then the first string is greater than the second string.

the following c# example code demonstrate us how can we compare two strings by ignoring their case.

C# Code:

Output:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.