Pages

Wednesday, September 14, 2011

Case insensitive string comparison

What will happen if you compare following two strings using equality operator (==)?

string a = "jayani";
string b = "Jayani"

a == b - False
It will say that two strings are not the same.

But what if you want to compare them in a case insensitive manner?
You can use String.Compare method for that.

String.Compare(a, b, true); // This will return zero which indicates that strings are similar.

Third parameter asks to do a case insensitive comparison.

No comments:

Post a Comment