Through this blog I will show you the tricks
to compare the string in C#.
Usually, When people compare the two strings (Don't know whether, if they are in
upper case or lower case), they do it like this..
string
FirstString = "GAURAV";
string SecondString =
"gaurav";
if (FirstString .ToUpper() == SecondString.ToUpper())
{
Response.Write("true");
}
Comparing the two string using the above code will increase the additional
memory allocation overhead on the compiler.
The above task can be accomplish by avoiding string allocation overhead like
this.
string
FirstString = "GAURAV";
string SecondString =
"gaurav";
if (FirstString.Equals(SecondString,
StringComparison.OrdinalIgnoreCase))
{
Response.Write("Matched");
}
In the above
code,StringComparison.OrdinalIgnoreCase will lead to compare the string by
ignoring it's case.
So, Now your code to compare the two strings:
if (FirstString .ToUpper() == SecondString.ToUpper())

FireMystPosted Dec 14, 2014, 4:05 AM
This blog benchmarks numerous ways to compare strings in C#, and proves which is the fastest: http://www.pvladov.com/2012/09/case-insensitive-string-comparison.html _