-3

How to compare a 2 string in different case like String a="Pawan"; String b="PAWAN"; how to compare using inbuilt method I am try to compare culture method but can not be compere so please provide a solution return result equal or not equal

2 Answers2

-1

Transform both to lowercase strings and compare after that

a.ToLower() == b.ToLower()
tchelidze
  • 8,050
  • 1
  • 29
  • 49
-1

Every answer so far was checking for equality, here is mine actually comparing:

switch(string.Compare(a, b, StringComparison.CurrentCultureIgnoreCase))
{
   case  1: Console.WriteLine("a is greater"); break;
   case  0: Console.WriteLine("a and b are equal"); break;
   case -1: Console.WriteLine("b is greater"); break;
}

You can test it here https://dotnetfiddle.net/h75xZ8

If you arent sure about the comparison, you can look it up here: https://msdn.microsoft.com/en-us/library/system.stringcomparison(v=vs.110).aspx

CSharpie
  • 9,195
  • 4
  • 44
  • 71