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
Asked
Active
Viewed 116 times
-3
-
By `compare` do you mean if they are equal or really compare in order to sort them? – CSharpie Aug 09 '17 at 11:11
-
@CSharpie `compare` and `really compare` - new word in string comparison history – tchelidze Aug 09 '17 at 11:12
-
Not to transform upper and lower case used any methods as inbuilt I don't know method name to compare directly without transfrom – Pawan Kumar Tiwari Oct 03 '17 at 04:11
2 Answers
-1
Transform both to lowercase strings and compare after that
a.ToLower() == b.ToLower()

tchelidze
- 8,050
- 1
- 29
- 49
-
-
-
OP asked for `Compare`, your solution only checks equality. Compare is used to sort things. – CSharpie Aug 09 '17 at 11:14
-
2
-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