String.Equals Method (String, String, StringComparison)
Determines whether two specified String objects have the same value. A parameter specifies the culture, case, and sort rules used in the comparison.
Assembly: mscorlib (in mscorlib.dll)
Public Shared Function Equals ( a As String, b As String, comparisonType As StringComparison ) As Boolean
Parameters
- a
-
Type:
System.String
The first string to compare, or null.
- b
-
Type:
System.String
The second string to compare, or null.
- comparisonType
-
Type:
System.StringComparison
One of the enumeration values that specifies the rules for the comparison.
Return Value
Type: System.Booleantrue if the value of the a parameter is equal to the value of the b parameter; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentException | comparisonType is not a StringComparison value. |
The comparisonType parameter indicates whether the comparison should use the current or invariant culture, honor or ignore the case of the two strings being compared, or use word or ordinal sort rules.
The following example compares four sets of words by using each member of the StringComparison enumeration. The comparisons use the conventions of the English (United States) and Sami (Upper Sweden) cultures. Note that the strings "encyclopædia" and "encyclopedia" are considered equivalent in the en-US culture but not in the Sami (Northern Sweden) culture.
Imports System.Globalization Imports System.Threading Module Example Public Sub Main() Dim cultureNames() As String = { "en-US", "se-SE" } Dim strings1() As String = { "case", "encyclopædia", "encyclopædia", "Archæology" } Dim strings2() As String = { "Case", "encyclopaedia", "encyclopedia" , "ARCHÆOLOGY" } Dim comparisons() As StringComparison = CType([Enum].GetValues(GetType(StringComparison)), StringComparison()) For Each cultureName In cultureNames Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName) Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name) For ctr As Integer = 0 To strings1.GetUpperBound(0) For Each comparison In comparisons Console.WriteLine(" {0} = {1} ({2}): {3}", strings1(ctr), strings2(ctr), comparison, String.Equals(strings1(ctr), strings2(ctr), comparison)) Next Console.WriteLine() Next Console.WriteLine() Next End Sub End Module ' The example displays the following output: ' Current Culture: en-US ' case = Case (CurrentCulture): False ' case = Case (CurrentCultureIgnoreCase): True ' case = Case (InvariantCulture): False ' case = Case (InvariantCultureIgnoreCase): True ' case = Case (Ordinal): False ' case = Case (OrdinalIgnoreCase): True ' ' encyclopædia = encyclopaedia (CurrentCulture): True ' encyclopædia = encyclopaedia (CurrentCultureIgnoreCase): True ' encyclopædia = encyclopaedia (InvariantCulture): True ' encyclopædia = encyclopaedia (InvariantCultureIgnoreCase): True ' encyclopædia = encyclopaedia (Ordinal): False ' encyclopædia = encyclopaedia (OrdinalIgnoreCase): False ' ' encyclopædia = encyclopedia (CurrentCulture): False ' encyclopædia = encyclopedia (CurrentCultureIgnoreCase): False ' encyclopædia = encyclopedia (InvariantCulture): False ' encyclopædia = encyclopedia (InvariantCultureIgnoreCase): False ' encyclopædia = encyclopedia (Ordinal): False ' encyclopædia = encyclopedia (OrdinalIgnoreCase): False ' ' Archæology = ARCHÆOLOGY (CurrentCulture): False ' Archæology = ARCHÆOLOGY (CurrentCultureIgnoreCase): True ' Archæology = ARCHÆOLOGY (InvariantCulture): False ' Archæology = ARCHÆOLOGY (InvariantCultureIgnoreCase): True ' Archæology = ARCHÆOLOGY (Ordinal): False ' Archæology = ARCHÆOLOGY (OrdinalIgnoreCase): True ' ' ' Current Culture: se-SE ' case = Case (CurrentCulture): False ' case = Case (CurrentCultureIgnoreCase): True ' case = Case (InvariantCulture): False ' case = Case (InvariantCultureIgnoreCase): True ' case = Case (Ordinal): False ' case = Case (OrdinalIgnoreCase): True ' ' encyclopædia = encyclopaedia (CurrentCulture): False ' encyclopædia = encyclopaedia (CurrentCultureIgnoreCase): False ' encyclopædia = encyclopaedia (InvariantCulture): True ' encyclopædia = encyclopaedia (InvariantCultureIgnoreCase): True ' encyclopædia = encyclopaedia (Ordinal): False ' encyclopædia = encyclopaedia (OrdinalIgnoreCase): False ' ' encyclopædia = encyclopedia (CurrentCulture): False ' encyclopædia = encyclopedia (CurrentCultureIgnoreCase): False ' encyclopædia = encyclopedia (InvariantCulture): False ' encyclopædia = encyclopedia (InvariantCultureIgnoreCase): False ' encyclopædia = encyclopedia (Ordinal): False ' encyclopædia = encyclopedia (OrdinalIgnoreCase): False ' ' Archæology = ARCHÆOLOGY (CurrentCulture): False ' Archæology = ARCHÆOLOGY (CurrentCultureIgnoreCase): True ' Archæology = ARCHÆOLOGY (InvariantCulture): False ' Archæology = ARCHÆOLOGY (InvariantCultureIgnoreCase): True ' Archæology = ARCHÆOLOGY (Ordinal): False ' Archæology = ARCHÆOLOGY (OrdinalIgnoreCase): True
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1