While comparing strings, you also have the added possibility to use or not use case sensitivity.
Consider the two strings:
string String1 ="India";
string String2 ="india";
There are 3 parameters to this method:
- String1
- String2
- Case Sensitivity
If you want to compare the strings, and you don't care to check for case sensitivity, you will use 'True'. If you do want to compare them, and take case sensitivity into consideration when checking them, you will use 'False'.
It will return an Integer value. if it returns 0, then the strings are equal to one another. If it returns -1, the strings are NOT equal to one another.
Example:
[1.]Compare using Ignoring Case Sensitivity
string String1 ="India";
string String2 ="india";
if (System.String.Compare(String1,String2,True)=0)
{
// put code here if the strings are the same
}
else
{
// put code here if the strings are the not same
}
[2.]Compare using Case Sensitivity
string String1 ="India";
string String2 ="india";
if (System.String.Compare(String1,String2,False)=0)
{
// put code here if the strings are the same
}
else
{
// put code here if the strings are the not same
}