C# String Compare(String, String, Boolean, CultureInfo)
Description
String Compare(String, String, Boolean, CultureInfo)
compares
two specified String objects, ignoring or honoring their case, and using
culture-specific information to influence the comparison, and returns
an integer that indicates their relative position in the sort order.
Syntax
String.Compare(String, String, Boolean, CultureInfo)
has the following syntax.
public static int Compare(
string strA,//from www .java2 s . c o m
string strB,
bool ignoreCase,
CultureInfo culture
)
Parameters
String.Compare(String, String, Boolean, CultureInfo)
has the following parameters.
strA
- The first string to compare.strB
- The second string to compare.ignoreCase
- true to ignore case during the comparison; otherwise, false.culture
- An object that supplies culture-specific comparison information.
Returns
String.Compare(String, String, Boolean, CultureInfo)
method returns A 32-bit signed integer that indicates the lexical relationship between
the two comparands. Value Condition Less than zero strA is less than strB.
Zero strA equals strB. Greater than zero strA is greater than strB.
Example
For example, a case-insensitive comparison of "animal" with "Ani-mal" (using a soft hyphen, or U+00AD) using the invariant culture indicates that the two strings are equivalent, as the following example shows.
using System;/*from w w w. j av a 2 s . c o m*/
using System.Globalization;
public class Example
{
public static void Main()
{
string s1 = "Ani\u00ADmal";
string s2 = "animal";
Console.WriteLine("Comparison of '{0}' and '{1}': {2}",
s1, s2, String.Compare(s1, s2, true,
CultureInfo.InvariantCulture));
}
}
The code above generates the following result.