How to IgnoreCase in C#/VB.NET String Comparison
Whether you like or not, life revolves around comparison . Here let us see how to compare two strings using Equals method.
Equals method takes two arguments - the string to be compared and the comparison type (Case Sensitive or Insensitive)
The following snippet gives a hint of both:
private static void StringCompExample()
{
string s1 = "MulTIpleCASE";
string s2 = "MultipleCase";
bool compare_result = false;
//case sensitive comparison
compare_result = s1.Equals(s2);
Console.WriteLine(compare_result.ToString ());
//case insensitive comparison
compare_result = s1.Equals(s2, StringComparison.InvariantCultureIgnoreCase);
Console.WriteLine(compare_result.ToString());
}
No comments:
Post a Comment