String.Equals メソッド (String, String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim a As String Dim b As String Dim returnValue As Boolean returnValue = String.Equals(a, b)
- a
String または null 参照 (Visual Basic では Nothing)。
- b
String または null 参照 (Visual Basic では Nothing)。
a の値が b の値と同じ場合は true。それ以外の場合は false。


' Sample for String.Equals(Object) ' String.Equals(String) ' String.Equals(String, String) Imports System Imports System.Text Class Sample Public Shared Sub Main() Dim sb As New StringBuilder("abcd") Dim str1 As [String] = "abcd" Dim str2 As [String] = Nothing Dim o2 As [Object] = Nothing Console.WriteLine() Console.WriteLine(" * The value of String str1 is '{0}'.", str1) Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()) Console.WriteLine() Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String.") Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb)) Console.WriteLine() Console.WriteLine("1b) String.Equals(Object). Object is a String.") str2 = sb.ToString() o2 = str2 Console.WriteLine(" * The value of Object o2 is '{0}'.", o2) Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2)) Console.WriteLine() Console.WriteLine(" 2) String.Equals(String)") Console.WriteLine(" * The value of String str2 is '{0}'.", str2) Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2)) Console.WriteLine() Console.WriteLine(" 3) String.Equals(String, String)") Console.WriteLine(" Is str1 equal to str2?: {0}", [String].Equals(str1, str2)) End Sub 'Main End Class 'Sample ' 'This example produces the following results: ' ' * The value of String str1 is 'abcd'. ' * The value of StringBuilder sb is 'abcd'. ' '1a) String.Equals(Object). Object is a StringBuilder, not a String. ' Is str1 equal to sb?: False ' '1b) String.Equals(Object). Object is a String. ' * The value of Object o2 is 'abcd'. ' Is str1 equal to o2?: True ' ' 2) String.Equals(String) ' * The value of String str2 is 'abcd'. ' Is str1 equal to str2?: True ' ' 3) String.Equals(String, String) ' Is str1 equal to str2?: True '
// Sample for String.Equals(Object) // String.Equals(String) // String.Equals(String, String) using System; using System.Text; class Sample { public static void Main() { StringBuilder sb = new StringBuilder("abcd"); String str1 = "abcd"; String str2 = null; Object o2 = null; Console.WriteLine(); Console.WriteLine(" * The value of String str1 is '{0}'.", str1); Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()); Console.WriteLine(); Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String."); Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb)); Console.WriteLine(); Console.WriteLine("1b) String.Equals(Object). Object is a String."); str2 = sb.ToString(); o2 = str2; Console.WriteLine(" * The value of Object o2 is '{0}'.", o2); Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2)); Console.WriteLine(); Console.WriteLine(" 2) String.Equals(String)"); Console.WriteLine(" * The value of String str2 is '{0}'.", str2); Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2)); Console.WriteLine(); Console.WriteLine(" 3) String.Equals(String, String)"); Console.WriteLine(" Is str1 equal to str2?: {0}", String.Equals(str1, str2)); } } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String.Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String.Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String.Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String.Equals(String, String) Is str1 equal to str2?: True */
// Sample for String::Equals(Object) // String::Equals(String) // String::Equals(String, String) using namespace System; using namespace System::Text; int main() { StringBuilder^ sb = gcnew StringBuilder( "abcd" ); String^ str1 = "abcd"; String^ str2 = nullptr; Object^ o2 = nullptr; Console::WriteLine(); Console::WriteLine( " * The value of String str1 is '{0}'.", str1 ); Console::WriteLine( " * The value of StringBuilder sb is '{0}'.", sb ); Console::WriteLine(); Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder, not a String." ); Console::WriteLine( " Is str1 equal to sb?: {0}", str1->Equals( sb ) ); Console::WriteLine(); Console::WriteLine( "1b) String::Equals(Object). Object is a String." ); str2 = sb->ToString(); o2 = str2; Console::WriteLine( " * The value of Object o2 is '{0}'.", o2 ); Console::WriteLine( " Is str1 equal to o2?: {0}", str1->Equals( o2 ) ); Console::WriteLine(); Console::WriteLine( " 2) String::Equals(String)" ); Console::WriteLine( " * The value of String str2 is '{0}'.", str2 ); Console::WriteLine( " Is str1 equal to str2?: {0}", str1->Equals( str2 ) ); Console::WriteLine(); Console::WriteLine( " 3) String::Equals(String, String)" ); Console::WriteLine( " Is str1 equal to str2?: {0}", String::Equals( str1, str2 ) ); } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String::Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String::Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String::Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String::Equals(String, String) Is str1 equal to str2?: True */
// Sample for String.Equals(Object) // String.Equals(String) // String.Equals(String, String) import System.*; import System.Text.*; class Sample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("abcd"); String str1 = "abcd"; String str2 = null; Object o2 = null; Console.WriteLine(); Console.WriteLine(" * The value of String str1 is '{0}'.", str1); Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()); Console.WriteLine(); Console.WriteLine("1a) String.Equals(Object). Object is a " + "StringBuilder, not a String."); Console.WriteLine(" Is str1 equal to sb?: {0}", System.Convert.ToString(str1.Equals(sb))); Console.WriteLine(); Console.WriteLine("1b) String.Equals(Object). Object is a String."); str2 = sb.ToString(); o2 = str2; Console.WriteLine(" * The value of Object o2 is '{0}'.", o2); Console.WriteLine(" Is str1 equal to o2?: {0}", System.Convert.ToString(str1.Equals(o2))); Console.WriteLine(); Console.WriteLine(" 2) String.Equals(String)"); Console.WriteLine(" * The value of String str2 is '{0}'.", str2); Console.WriteLine(" Is str1 equal to str2?: {0}", System.Convert.ToString(str1.Equals(str2))); Console.WriteLine(); Console.WriteLine(" 3) String.Equals(String, String)"); Console.WriteLine(" Is str1 equal to str2?: {0}", System.Convert.ToString(String.Equals(str1, str2))); } //main } //Sample /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String.Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String.Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String.Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String.Equals(String, String) Is str1 equal to str2?: True */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Equals メソッド (String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim value As String Dim returnValue As Boolean returnValue = instance.Equals(value)
戻り値
value パラメータの値がこのインスタンスと同じ場合は true。それ以外の場合は false。



' Override the 'FormatDataValue' method. Protected Overrides Function FormatDataValue(ByVal dataValue As Object) As String Dim myString As String = dataValue.ToString() ' Get the DataFormat. Dim myFormat As String = Me.DataFormatString Dim mySubString As String = myFormat.Substring(2, 3) ' Check for the currency format. If mySubString.Equals(":c}") Then Return "$" & myString Else Return myString End If End Function
// Override the 'FormatDataValue' method. protected override string FormatDataValue(object dataValue) { string myString = dataValue.ToString(); // Get the DataFormat. string myFormat = this.DataFormatString; string mySubString = myFormat.Substring(2,3); // Check for the currency format. if (mySubString.Equals(":c}")) { return "$" + myString; } else return myString; }
// Override the 'FormatDataValue' method. virtual String^ FormatDataValue( Object^ dataValue ) override { String^ myString = dataValue->ToString(); // Get the DataFormat. String^ myFormat = this->DataFormatString; String^ mySubString = myFormat->Substring( 2, 3 ); // Check for the currency format. if ( mySubString->Equals( ":c}" ) ) { return String::Format( "${0}", myString ); } else return myString; }
// Override the 'FormatDataValue' method. protected String FormatDataValue(Object dataValue) { String myString = dataValue.ToString(); // Get the DataFormat. String myFormat = this.get_DataFormatString(); String mySubString = myFormat.Substring(2, 3); // Check for the currency format. if (mySubString.Equals(":c}")) { return "$" + myString; } else { return myString; } } //FormatDataValue

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Equals メソッド (String, StringComparison)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim value As String Dim comparisonType As StringComparison Dim returnValue As Boolean returnValue = instance.Equals(value, comparisonType)
- comparisonType
System.StringComparison 値の 1 つ。
value パラメータの値がこの文字列と同じ場合は true。それ以外の場合は false。


comparisonType パラメータは、比較の種類 (現在のカルチャを使用するかインバリアント カルチャを使用するか、比較対象値の大文字と小文字を区別するか、並べ替え規則に単語を使用するか序数を使用するか) を指定します。

Equals メソッドを 3 とおりの方法で使用し、String オブジェクトと StringBuilder オブジェクトとが等しいかどうかを判断するコード例を次に示します。選択したカルチャ、大文字と小文字の区別、比較の種類 (序数ベースにしたかどうか) が実行結果に影響します。
' This example demonstrates the ' System.String.Equals(String, StringComparison) method. Imports System Imports System.Threading Class Sample Public Shared Sub Main() Dim intro As String = "Compare three versions of the letter I using different " + "values of StringComparison." ' Define an array of strings where each element contains a version of the ' letter I. (An array of strings is used so you can easily modify this ' code example to test additional or different combinations of strings.) Dim threeIs(2) As String ' LATIN SMALL LETTER I (U+0069) threeIs(0) = "i" ' LATIN SMALL LETTER DOTLESS I (U+0131) threeIs(1) = "ı" ' LATIN CAPITAL LETTER I (U+0049) threeIs(2) = "I" Dim unicodeNames As String() = { _ "LATIN SMALL LETTER I (U+0069)", _ "LATIN SMALL LETTER DOTLESS I (U+0131)", _ "LATIN CAPITAL LETTER I (U+0049)" } Dim scValues As StringComparison() = { _ StringComparison.CurrentCulture, _ StringComparison.CurrentCultureIgnoreCase, _ StringComparison.InvariantCulture, _ StringComparison.InvariantCultureIgnoreCase, _ StringComparison.Ordinal, _ StringComparison.OrdinalIgnoreCase } ' Console.Clear() Console.WriteLine(intro) ' Display the current culture because the culture-specific comparisons ' can produce different results with different cultures. Console.WriteLine("The current culture is {0}." & vbCrLf, _ Thread.CurrentThread.CurrentCulture.Name) ' Determine whether three versions of the letter I are equal to each other. Dim sc As StringComparison For Each sc In scValues Console.WriteLine("StringComparison.{0}:", sc) ' LATIN SMALL LETTER I (U+0069) : LATIN SMALL LETTER DOTLESS I (U+0131) Test(0, 1, sc, threeIs, unicodeNames) ' LATIN SMALL LETTER I (U+0069) : LATIN CAPITAL LETTER I (U+0049) Test(0, 2, sc, threeIs, unicodeNames) ' LATIN SMALL LETTER DOTLESS I (U+0131) : LATIN CAPITAL LETTER I (U+0049) Test(1, 2, sc, threeIs, unicodeNames) Console.WriteLine() Next sc End Sub 'Main Protected Shared Sub Test(ByVal x As Integer, ByVal y As Integer, _ ByVal comparison As StringComparison, _ ByVal testI() As String, ByVal testNames() As String) Dim resultFmt As String = "{0} is {1}equal to {2}" Dim result As String = "not " ' If testI(x).Equals(testI(y), comparison) Then result = "" End If Console.WriteLine(resultFmt, testNames(x), result, testNames(y)) End Sub 'Test End Class 'Sample ' 'This code example produces the following results: ' 'Compare three versions of the letter I using different values of StringComparison. 'The current culture is en-US. ' 'StringComparison.CurrentCulture: 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) 'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) ' 'StringComparison.CurrentCultureIgnoreCase: 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) 'LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) 'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) ' 'StringComparison.InvariantCulture: 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) 'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) ' 'StringComparison.InvariantCultureIgnoreCase: 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) 'LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) 'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) ' 'StringComparison.Ordinal: 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) 'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) ' 'StringComparison.OrdinalIgnoreCase: 'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) 'LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) 'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) ' '
// This example demonstrates the // System.String.Equals(String, StringComparison) method. using System; using System.Threading; class Sample { public static void Main() { string intro = "Compare three versions of the letter I using different " + "values of StringComparison."; // Define an array of strings where each element contains a version of the // letter I. (An array of strings is used so you can easily modify this // code example to test additional or different combinations of strings.) string[] threeIs = new string[3]; // LATIN SMALL LETTER I (U+0069) threeIs[0] = "\u0069"; // LATIN SMALL LETTER DOTLESS I (U+0131) threeIs[1] = "\u0131"; // LATIN CAPITAL LETTER I (U+0049) threeIs[2] = "\u0049"; string[] unicodeNames = { "LATIN SMALL LETTER I (U+0069)", "LATIN SMALL LETTER DOTLESS I (U+0131)", "LATIN CAPITAL LETTER I (U+0049)" }; StringComparison[] scValues = { StringComparison.CurrentCulture, StringComparison.CurrentCultureIgnoreCase, StringComparison.InvariantCulture, StringComparison.InvariantCultureIgnoreCase, StringComparison.Ordinal, StringComparison.OrdinalIgnoreCase }; // Console.Clear(); Console.WriteLine(intro); // Display the current culture because the culture-specific comparisons // can produce different results with different cultures. Console.WriteLine("The current culture is {0}.\n", Thread.CurrentThread.CurrentCulture.Name); // Determine whether three versions of the letter I are equal to each other. foreach (StringComparison sc in scValues) { Console.WriteLine("StringComparison.{0}:", sc); // LATIN SMALL LETTER I (U+0069) : LATIN SMALL LETTER DOTLESS I (U+0131) Test(0, 1, sc, threeIs, unicodeNames); // LATIN SMALL LETTER I (U+0069) : LATIN CAPITAL LETTER I (U+0049) Test(0, 2, sc, threeIs, unicodeNames); // LATIN SMALL LETTER DOTLESS I (U+0131) : LATIN CAPITAL LETTER I (U+0049) Test(1, 2, sc, threeIs, unicodeNames); Console.WriteLine(); } } protected static void Test(int x, int y, StringComparison comparison, string[] testI, string[] testNames) { string resultFmt = "{0} is {1}equal to {2}"; string result = "not "; // if (testI[x].Equals(testI[y], comparison)) result = ""; Console.WriteLine(resultFmt, testNames[x], result, testNames[y]); } } /* This code example produces the following results: Compare three versions of the letter I using different values of StringComparison. The current culture is en-US. StringComparison.CurrentCulture: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.CurrentCultureIgnoreCase: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.InvariantCulture: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.InvariantCultureIgnoreCase: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.Ordinal: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.OrdinalIgnoreCase: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) */
// This example demonstrates the // System.String.Equals(String, StringComparison) method. using namespace System; using namespace System::Threading; void Test(int testStringIndex, int comparisonStringIndex, StringComparison comparison, array<String^>^ testI, array<String^>^ testNames) { String^ resultFormat = "{0} is {1}equal to {2}"; String^ resultString = "not "; if (testI[testStringIndex]->Equals(testI[comparisonStringIndex] , comparison)) { resultString = ""; } Console::WriteLine(resultFormat, testNames[testStringIndex], resultString, testNames[comparisonStringIndex]); } int main() { String^ introMessage = "Compare three versions of the letter I using different " + "values of StringComparison."; // Define an array of strings where each element contains a version of // the letter I. (An array of strings is used so you can easily modify // this code example to test additional or different combinations of // strings.) array<String^>^ letterVariation = gcnew array<String^>(3); // LATIN SMALL LETTER I (U+0069) letterVariation[0] = "i"; // LATIN SMALL LETTER DOTLESS I (U+0131) letterVariation[1] = L"\u0131"; // LATIN CAPITAL LETTER I (U+0049) letterVariation[2] = "I"; array<String^>^ unicodeNames = { "LATIN SMALL LETTER I (U+0069)", "LATIN SMALL LETTER DOTLESS I (U+0131)", "LATIN CAPITAL LETTER I (U+0049)"}; array<StringComparison>^ comparisonValues = { StringComparison::CurrentCulture, StringComparison::CurrentCultureIgnoreCase, StringComparison::InvariantCulture, StringComparison::InvariantCultureIgnoreCase, StringComparison::Ordinal, StringComparison::OrdinalIgnoreCase}; Console::Clear(); Console::WriteLine(introMessage); // Display the current culture because the culture-specific comparisons // can produce different results with different cultures. Console::WriteLine("The current culture is {0}.\n", Thread::CurrentThread->CurrentCulture->Name); // Determine whether three versions of the letter I are equal to each // other. for each (StringComparison stringCmp in comparisonValues) { Console::WriteLine("StringComparison.{0}:", stringCmp); // LATIN SMALL LETTER I (U+0069) : LATIN SMALL LETTER DOTLESS I // (U+0131) Test(0, 1, stringCmp, letterVariation, unicodeNames); // LATIN SMALL LETTER I (U+0069) : LATIN CAPITAL LETTER I (U+0049) Test(0, 2, stringCmp, letterVariation, unicodeNames); // LATIN SMALL LETTER DOTLESS I (U+0131) : LATIN CAPITAL LETTER I // (U+0049) Test(1, 2, stringCmp, letterVariation, unicodeNames); Console::WriteLine(); } } /* This code example produces the following results: Compare three versions of the letter I using different values of StringComparison. The current culture is en-US. StringComparison.CurrentCulture: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.CurrentCultureIgnoreCase: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.InvariantCulture: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.InvariantCultureIgnoreCase: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.Ordinal: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) StringComparison.OrdinalIgnoreCase: LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131) LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049) LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049) */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Equals メソッド (Object)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim obj As Object Dim returnValue As Boolean returnValue = instance.Equals(obj)
戻り値
obj が String で、このインスタンスと同じ値を保持している場合は true。それ以外の場合は false。



' Sample for String.Equals(Object) ' String.Equals(String) ' String.Equals(String, String) Imports System Imports System.Text Class Sample Public Shared Sub Main() Dim sb As New StringBuilder("abcd") Dim str1 As [String] = "abcd" Dim str2 As [String] = Nothing Dim o2 As [Object] = Nothing Console.WriteLine() Console.WriteLine(" * The value of String str1 is '{0}'.", str1) Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()) Console.WriteLine() Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String.") Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb)) Console.WriteLine() Console.WriteLine("1b) String.Equals(Object). Object is a String.") str2 = sb.ToString() o2 = str2 Console.WriteLine(" * The value of Object o2 is '{0}'.", o2) Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2)) Console.WriteLine() Console.WriteLine(" 2) String.Equals(String)") Console.WriteLine(" * The value of String str2 is '{0}'.", str2) Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2)) Console.WriteLine() Console.WriteLine(" 3) String.Equals(String, String)") Console.WriteLine(" Is str1 equal to str2?: {0}", [String].Equals(str1, str2)) End Sub 'Main End Class 'Sample ' 'This example produces the following results: ' ' * The value of String str1 is 'abcd'. ' * The value of StringBuilder sb is 'abcd'. ' '1a) String.Equals(Object). Object is a StringBuilder, not a String. ' Is str1 equal to sb?: False ' '1b) String.Equals(Object). Object is a String. ' * The value of Object o2 is 'abcd'. ' Is str1 equal to o2?: True ' ' 2) String.Equals(String) ' * The value of String str2 is 'abcd'. ' Is str1 equal to str2?: True ' ' 3) String.Equals(String, String) ' Is str1 equal to str2?: True '
// Sample for String.Equals(Object) // String.Equals(String) // String.Equals(String, String) using System; using System.Text; class Sample { public static void Main() { StringBuilder sb = new StringBuilder("abcd"); String str1 = "abcd"; String str2 = null; Object o2 = null; Console.WriteLine(); Console.WriteLine(" * The value of String str1 is '{0}'.", str1); Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()); Console.WriteLine(); Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String."); Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb)); Console.WriteLine(); Console.WriteLine("1b) String.Equals(Object). Object is a String."); str2 = sb.ToString(); o2 = str2; Console.WriteLine(" * The value of Object o2 is '{0}'.", o2); Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2)); Console.WriteLine(); Console.WriteLine(" 2) String.Equals(String)"); Console.WriteLine(" * The value of String str2 is '{0}'.", str2); Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2)); Console.WriteLine(); Console.WriteLine(" 3) String.Equals(String, String)"); Console.WriteLine(" Is str1 equal to str2?: {0}", String.Equals(str1, str2)); } } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String.Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String.Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String.Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String.Equals(String, String) Is str1 equal to str2?: True */
// Sample for String::Equals(Object) // String::Equals(String) // String::Equals(String, String) using namespace System; using namespace System::Text; int main() { StringBuilder^ sb = gcnew StringBuilder( "abcd" ); String^ str1 = "abcd"; String^ str2 = nullptr; Object^ o2 = nullptr; Console::WriteLine(); Console::WriteLine( " * The value of String str1 is '{0}'.", str1 ); Console::WriteLine( " * The value of StringBuilder sb is '{0}'.", sb ); Console::WriteLine(); Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder, not a String." ); Console::WriteLine( " Is str1 equal to sb?: {0}", str1->Equals( sb ) ); Console::WriteLine(); Console::WriteLine( "1b) String::Equals(Object). Object is a String." ); str2 = sb->ToString(); o2 = str2; Console::WriteLine( " * The value of Object o2 is '{0}'.", o2 ); Console::WriteLine( " Is str1 equal to o2?: {0}", str1->Equals( o2 ) ); Console::WriteLine(); Console::WriteLine( " 2) String::Equals(String)" ); Console::WriteLine( " * The value of String str2 is '{0}'.", str2 ); Console::WriteLine( " Is str1 equal to str2?: {0}", str1->Equals( str2 ) ); Console::WriteLine(); Console::WriteLine( " 3) String::Equals(String, String)" ); Console::WriteLine( " Is str1 equal to str2?: {0}", String::Equals( str1, str2 ) ); } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String::Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String::Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String::Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String::Equals(String, String) Is str1 equal to str2?: True */
// Sample for String.Equals(Object) // String.Equals(String) // String.Equals(String, String) import System.*; import System.Text.*; class Sample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("abcd"); String str1 = "abcd"; String str2 = null; Object o2 = null; Console.WriteLine(); Console.WriteLine(" * The value of String str1 is '{0}'.", str1); Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()); Console.WriteLine(); Console.WriteLine("1a) String.Equals(Object). Object is a " + "StringBuilder, not a String."); Console.WriteLine(" Is str1 equal to sb?: {0}", System.Convert.ToString(str1.Equals(sb))); Console.WriteLine(); Console.WriteLine("1b) String.Equals(Object). Object is a String."); str2 = sb.ToString(); o2 = str2; Console.WriteLine(" * The value of Object o2 is '{0}'.", o2); Console.WriteLine(" Is str1 equal to o2?: {0}", System.Convert.ToString(str1.Equals(o2))); Console.WriteLine(); Console.WriteLine(" 2) String.Equals(String)"); Console.WriteLine(" * The value of String str2 is '{0}'.", str2); Console.WriteLine(" Is str1 equal to str2?: {0}", System.Convert.ToString(str1.Equals(str2))); Console.WriteLine(); Console.WriteLine(" 3) String.Equals(String, String)"); Console.WriteLine(" Is str1 equal to str2?: {0}", System.Convert.ToString(String.Equals(str1, str2))); } //main } //Sample /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String.Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String.Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String.Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String.Equals(String, String) Is str1 equal to str2?: True */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Equals メソッド

名前 | 説明 |
---|---|
String.Equals (Object) | String のこのインスタンスと、指定したオブジェクトの値が同一かどうかを判断します。String オブジェクトを指定する必要があります。 .NET Compact Framework によってサポートされています。 |
String.Equals (String) | このインスタンスと、指定した別の String の値が同一かどうかを判断します。 .NET Compact Framework によってサポートされています。 |
String.Equals (Object, Object) | 指定した Object インスタンスが等しいかどうかを判断します。 |
String.Equals (String, String) | 指定した 2 つの String オブジェクトの値が同一かどうかを判断します。 .NET Compact Framework によってサポートされています。 |
String.Equals (String, StringComparison) | この文字列と、指定した String オブジェクトの値が同一かどうかを判断します。比較に使用するカルチャ、大文字と小文字の区別、および、並べ替え規則をパラメータで指定します。 .NET Compact Framework によってサポートされています。 |
String.Equals (String, String, StringComparison) | 指定した 2 つの String オブジェクトの値が同一かどうかを判断します。比較に使用するカルチャ、大文字と小文字の区別、および、並べ替え規則をパラメータで指定します。 .NET Compact Framework によってサポートされています。 |

String.Equals メソッド (String, String, StringComparison)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Shared Function Equals ( _ a As String, _ b As String, _ comparisonType As StringComparison _ ) As Boolean
Dim a As String Dim b As String Dim comparisonType As StringComparison Dim returnValue As Boolean returnValue = String.Equals(a, b, comparisonType)
public static function Equals ( a : String, b : String, comparisonType : StringComparison ) : boolean
- a
String オブジェクトまたは null 参照 (Visual Basic では Nothing)。
- b
String オブジェクトまたは null 参照 (Visual Basic では Nothing)。
- comparisonType
System.StringComparison 値の 1 つ。
a パラメータの値が b パラメータの値に等しい場合は true。それ以外の場合は false。


comparisonType パラメータは、比較の種類 (現在のカルチャを使用するかインバリアント カルチャを使用するか、比較対象値の大文字と小文字を区別するか、並べ替え規則に単語を使用するか序数を使用するか) を指定します。

Equals メソッドを 3 とおりの方法で使用し、String オブジェクトと StringBuilder オブジェクトとが等しいかどうかを判断するコード例を次に示します。
' Sample for String.Equals(Object) ' String.Equals(String) ' String.Equals(String, String) Imports System Imports System.Text Class Sample Public Shared Sub Main() Dim sb As New StringBuilder("abcd") Dim str1 As [String] = "abcd" Dim str2 As [String] = Nothing Dim o2 As [Object] = Nothing Console.WriteLine() Console.WriteLine(" * The value of String str1 is '{0}'.", str1) Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()) Console.WriteLine() Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String.") Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb)) Console.WriteLine() Console.WriteLine("1b) String.Equals(Object). Object is a String.") str2 = sb.ToString() o2 = str2 Console.WriteLine(" * The value of Object o2 is '{0}'.", o2) Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2)) Console.WriteLine() Console.WriteLine(" 2) String.Equals(String)") Console.WriteLine(" * The value of String str2 is '{0}'.", str2) Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2)) Console.WriteLine() Console.WriteLine(" 3) String.Equals(String, String)") Console.WriteLine(" Is str1 equal to str2?: {0}", [String].Equals(str1, str2)) End Sub 'Main End Class 'Sample ' 'This example produces the following results: ' ' * The value of String str1 is 'abcd'. ' * The value of StringBuilder sb is 'abcd'. ' '1a) String.Equals(Object). Object is a StringBuilder, not a String. ' Is str1 equal to sb?: False ' '1b) String.Equals(Object). Object is a String. ' * The value of Object o2 is 'abcd'. ' Is str1 equal to o2?: True ' ' 2) String.Equals(String) ' * The value of String str2 is 'abcd'. ' Is str1 equal to str2?: True ' ' 3) String.Equals(String, String) ' Is str1 equal to str2?: True '
// Sample for String.Equals(Object) // String.Equals(String) // String.Equals(String, String) using System; using System.Text; class Sample { public static void Main() { StringBuilder sb = new StringBuilder("abcd"); String str1 = "abcd"; String str2 = null; Object o2 = null; Console.WriteLine(); Console.WriteLine(" * The value of String str1 is '{0}'.", str1); Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()); Console.WriteLine(); Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String."); Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb)); Console.WriteLine(); Console.WriteLine("1b) String.Equals(Object). Object is a String."); str2 = sb.ToString(); o2 = str2; Console.WriteLine(" * The value of Object o2 is '{0}'.", o2); Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2)); Console.WriteLine(); Console.WriteLine(" 2) String.Equals(String)"); Console.WriteLine(" * The value of String str2 is '{0}'.", str2); Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2)); Console.WriteLine(); Console.WriteLine(" 3) String.Equals(String, String)"); Console.WriteLine(" Is str1 equal to str2?: {0}", String.Equals(str1, str2)); } } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String.Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String.Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String.Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String.Equals(String, String) Is str1 equal to str2?: True */
// Sample for String::Equals(Object) // String::Equals(String) // String::Equals(String, String) using namespace System; using namespace System::Text; int main() { StringBuilder^ sb = gcnew StringBuilder( "abcd" ); String^ str1 = "abcd"; String^ str2 = nullptr; Object^ o2 = nullptr; Console::WriteLine(); Console::WriteLine( " * The value of String str1 is '{0}'.", str1 ); Console::WriteLine( " * The value of StringBuilder sb is '{0}'.", sb ); Console::WriteLine(); Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder, not a String." ); Console::WriteLine( " Is str1 equal to sb?: {0}", str1->Equals( sb ) ); Console::WriteLine(); Console::WriteLine( "1b) String::Equals(Object). Object is a String." ); str2 = sb->ToString(); o2 = str2; Console::WriteLine( " * The value of Object o2 is '{0}'.", o2 ); Console::WriteLine( " Is str1 equal to o2?: {0}", str1->Equals( o2 ) ); Console::WriteLine(); Console::WriteLine( " 2) String::Equals(String)" ); Console::WriteLine( " * The value of String str2 is '{0}'.", str2 ); Console::WriteLine( " Is str1 equal to str2?: {0}", str1->Equals( str2 ) ); Console::WriteLine(); Console::WriteLine( " 3) String::Equals(String, String)" ); Console::WriteLine( " Is str1 equal to str2?: {0}", String::Equals( str1, str2 ) ); } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String::Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String::Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String::Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String::Equals(String, String) Is str1 equal to str2?: True */
// Sample for String.Equals(Object) // String.Equals(String) // String.Equals(String, String) import System.*; import System.Text.*; class Sample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("abcd"); String str1 = "abcd"; String str2 = null; Object o2 = null; Console.WriteLine(); Console.WriteLine(" * The value of String str1 is '{0}'.", str1); Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString()); Console.WriteLine(); Console.WriteLine("1a) String.Equals(Object). Object is a " + "StringBuilder, not a String."); Console.WriteLine(" Is str1 equal to sb?: {0}", System.Convert.ToString(str1.Equals(sb))); Console.WriteLine(); Console.WriteLine("1b) String.Equals(Object). Object is a String."); str2 = sb.ToString(); o2 = str2; Console.WriteLine(" * The value of Object o2 is '{0}'.", o2); Console.WriteLine(" Is str1 equal to o2?: {0}", System.Convert.ToString(str1.Equals(o2))); Console.WriteLine(); Console.WriteLine(" 2) String.Equals(String)"); Console.WriteLine(" * The value of String str2 is '{0}'.", str2); Console.WriteLine(" Is str1 equal to str2?: {0}", System.Convert.ToString(str1.Equals(str2))); Console.WriteLine(); Console.WriteLine(" 3) String.Equals(String, String)"); Console.WriteLine(" Is str1 equal to str2?: {0}", System.Convert.ToString(String.Equals(str1, str2))); } //main } //Sample /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String.Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String.Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String.Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String.Equals(String, String) Is str1 equal to str2?: True */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からString.Equalsを検索する場合は、下記のリンクをクリックしてください。

- String.Equalsのページへのリンク