C Equals 반대 - C Equals bandae

JSTL의 비교연산, ep, ne, empty

[의미]

1. eq = equal (==)

2. ne = not equal (!=)

3. empty = list,map등의 객체가 값이 있다,없다를 구분(ex)empty, !empty)

[사용예시]

[eq]

 null

  <c:if test="${ null eq columnName }">

 숫자

  <c:if test="${ 0 eq columnName }">

 문자

  <c:if test="${ '0' eq columnName }">

[ne (!=)]

 null

  <c:if test="${ null ne columnName }"> 

 숫자

  <c:if test="${ 0 ne columnName }"> 

 문자

  <c:if test="${ '0' ne columnName }">

[empty]

 객체의 값이 비어있다.

 <c:if test="${ empty  columnMap}">

객체의 값이 있다.

 <c:if test="${ !empty  columnMap}">


[실제 적용 소스]

C Equals 반대 - C Equals bandae

[출처] eq, ne, empty 사용|작성자 맛동산

[출처] eq, ne, empty 사용|작성자 맛동산

주요 콘텐츠로 건너뛰기

이 브라우저는 더 이상 지원되지 않습니다.

최신 기능, 보안 업데이트, 기술 지원을 이용하려면 Microsoft Edge로 업그레이드하세요.

String.Equals 메서드

  • 참조

정의

이 문서의 내용

오버로드

Equals(String, StringComparison)

이 문자열과 지정한 String 개체의 값이 같은지를 확인합니다. 매개 변수는 비교에 사용되는 문화권, 대/소문자 및 정렬 규칙을 지정합니다.

public:
 bool Equals(System::String ^ value, StringComparison comparisonType);
public bool Equals (string value, StringComparison comparisonType);
public bool Equals (string? value, StringComparison comparisonType);
override this.Equals : string * StringComparison -> bool
Public Function Equals (value As String, comparisonType As StringComparison) As Boolean

매개 변수

value String

이 인스턴스와 비교할 문자열입니다.

반환

Boolean

true 매개 변수와 이 문자열의 값이 같으면 value이고, 그러지 않으면 false입니다.

예외

예제

다음 예제에서는 대문자 "I", 소문자 "i" 및 점 없는 "ı"로 구성 된 문자열 배열을 만듭니다. 그런 다음 메서드를 호출 Equals(String, StringComparison) 하 여 가능한 각 열거형 값을 사용 하 여 비교 StringComparison 합니다.

using System;

class Sample 
{
   public static void Main() 
   {
      // Define a string array with the following three "I" characters:
      //      U+0069, U+0131, and U+0049.  
      string[] threeIs = { "i", "ı", "I" };
      // Define Type object representing StringComparison type.
      Type scType = typeof(StringComparison);  
      
      // Show the current culture (for culture-sensitive string comparisons).
      Console.WriteLine("The current culture is {0}.\n", 
                        System.Globalization.CultureInfo.CurrentCulture.Name);
        
      // Perform comparisons using each StringComparison member. 
      foreach (string scName in Enum.GetNames(scType))
      {
         StringComparison sc = (StringComparison) Enum.Parse(scType, scName);
         Console.WriteLine("Comparisons using {0}:", sc);
         // Compare each character in character array.
         for (int ctr = 0; ctr <= 1; ctr++)
         {
            string instanceChar = threeIs[ctr];
            for (int innerCtr = ctr + 1; innerCtr <= threeIs.GetUpperBound(0); innerCtr++)
            {
               string otherChar = threeIs[innerCtr];
               Console.WriteLine("{0} (U+{1}) = {2} (U+{3}): {4}", 
                                 instanceChar, Convert.ToInt16(Char.Parse(instanceChar)).ToString("X4"), 
                                 otherChar, Convert.ToInt16(Char.Parse(otherChar)).ToString("X4"), 
                                 instanceChar.Equals(otherChar, sc));
            }
            Console.WriteLine();
         }
      }   
   }
}
// The example displays the following output:
//       The current culture is en-US.
//       
//       Comparisons using CurrentCulture:
//       i (U+0069) = i (U+0131): False
//       i (U+0069) = I (U+0049): False
//       
//       i (U+0131) = I (U+0049): False
//       
//       Comparisons using CurrentCultureIgnoreCase:
//       i (U+0069) = i (U+0131): False
//       i (U+0069) = I (U+0049): True
//       
//       i (U+0131) = I (U+0049): False
//       
//       Comparisons using InvariantCulture:
//       i (U+0069) = i (U+0131): False
//       i (U+0069) = I (U+0049): False
//       
//       i (U+0131) = I (U+0049): False
//       
//       Comparisons using InvariantCultureIgnoreCase:
//       i (U+0069) = i (U+0131): False
//       i (U+0069) = I (U+0049): True
//       
//       i (U+0131) = I (U+0049): False
//       
//       Comparisons using Ordinal:
//       i (U+0069) = i (U+0131): False
//       i (U+0069) = I (U+0049): False
//       
//       i (U+0131) = I (U+0049): False
//       
//       Comparisons using OrdinalIgnoreCase:
//       i (U+0069) = i (U+0131): False
//       i (U+0069) = I (U+0049): True
//       
//       i (U+0131) = I (U+0049): False
Class Sample
   Public Shared Sub Main() 
      ' Define a string array with the following three "I" characters:
      '      U+0069, U+0131, and U+0049.  
      Dim threeIs() As String = { "i", "ı", "I" }
      ' Define Type object representing StringComparison type.
      Dim scType As Type = GetType(StringComparison)  
      
      ' Show the current culture (for culture-sensitive string comparisons).
      Console.WriteLine("The current culture is {0}." & vbCrLf, _
                        System.Globalization.CultureInfo.CurrentCulture.Name)
        
      ' Perform comparisons using each StringComparison member. 
      For Each scName As String In [Enum].GetNames(scType)
         Dim sc As StringComparison = [Enum].Parse(scType, scName)
         Console.WriteLine("Comparisons using {0}:", sc)
         ' Compare each character in character array.
         For ctr As Integer = 0 To 1
            Dim instanceChar As String = threeIs(ctr)
            For innerCtr As Integer = ctr + 1 To threeIs.GetUpperBound(0)
               Dim otherChar As STring = threeIs(innerCtr)
               Console.WriteLine("{0} (U+{1}) = {2} (U+{3}): {4}", _
                                 instanceChar, Convert.ToInt16(Char.Parse(instanceChar)).ToString("X4"), _
                                 otherChar, Convert.ToInt16(Char.Parse(otherChar)).ToString("X4"), _
                                 instanceChar.Equals(otherChar, sc))
            Next
            Console.WriteLine()
         Next
      Next              
   End Sub
End Class
' The example displays the following output:
'       The current culture is en-US.
'       
'       Comparisons using CurrentCulture:
'       i (U+0069) = i (U+0131): False
'       i (U+0069) = I (U+0049): False
'       
'       i (U+0131) = I (U+0049): False
'       
'       Comparisons using CurrentCultureIgnoreCase:
'       i (U+0069) = i (U+0131): False
'       i (U+0069) = I (U+0049): True
'       
'       i (U+0131) = I (U+0049): False
'       
'       Comparisons using InvariantCulture:
'       i (U+0069) = i (U+0131): False
'       i (U+0069) = I (U+0049): False
'       
'       i (U+0131) = I (U+0049): False
'       
'       Comparisons using InvariantCultureIgnoreCase:
'       i (U+0069) = i (U+0131): False
'       i (U+0069) = I (U+0049): True
'       
'       i (U+0131) = I (U+0049): False
'       
'       Comparisons using Ordinal:
'       i (U+0069) = i (U+0131): False
'       i (U+0069) = I (U+0049): False
'       
'       i (U+0131) = I (U+0049): False
'       
'       Comparisons using OrdinalIgnoreCase:
'       i (U+0069) = i (U+0131): False
'       i (U+0069) = I (U+0049): True
'       
'       i (U+0131) = I (U+0049): False

다음 예제에서는 열거형의 각 멤버를 사용 하 여 4 개의 단어 집합을 비교 합니다 StringComparison . 비교에서는 영어 (미국) 및 라프어 (Upper 스웨덴) 문화권의 규칙을 사용 합니다. 문자열 "encyclopædia" 및 "encyclopaedia"는 en-us 문화권에서 동일 하 게 간주 되지만 Sami (북부 스웨덴) 문화권이 아닌 것으로 간주 됩니다.

using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      String[] cultureNames = { "en-US", "se-SE" };
      String[] strings1 = { "case",  "encyclopædia",  
                            "encyclopædia", "Archæology" };
      String[] strings2 = { "Case", "encyclopaedia", 
                            "encyclopedia" , "ARCHÆOLOGY" };
      StringComparison[] comparisons = (StringComparison[]) Enum.GetValues(typeof(StringComparison));
      
      foreach (var cultureName in cultureNames) {
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
         Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
         for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++) {
            foreach (var comparison in comparisons) 
               Console.WriteLine("   {0} = {1} ({2}): {3}", strings1[ctr],
                                 strings2[ctr], comparison, 
                                 strings1[ctr].Equals(strings2[ctr], comparison));

            Console.WriteLine();         
         }
         Console.WriteLine();
      }
   }
}
// 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
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, 
                                 strings1(ctr).Equals(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

설명

comparisonType매개 변수는 비교 시 현재 또는 고정 문화권을 사용 해야 하는지 여부를 지정 하 고 비교 하는 두 문자열의 대/소문자를 그대로 사용 하거나 무시 하거나 단어 또는 서 수 정렬 규칙을 사용 합니다.

추가 정보

  • CompareOrdinal(String, String)

적용 대상

Equals(String, String)

지정된 두 String 개체의 값이 같은지를 확인합니다.

public:
 static bool Equals(System::String ^ a, System::String ^ b);
public static bool Equals (string a, string b);
public static bool Equals (string? a, string? b);
static member Equals : string * string -> bool
Public Shared Function Equals (a As String, b As String) As Boolean

매개 변수

a String

비교할 첫 번째 문자열 또는 null입니다.

b String

비교할 두 번째 문자열 또는 null입니다.

반환

Boolean

true의 값이 a의 값과 같으면 b이고, 그렇지 않으면 false입니다. abnull인 경우 이 메서드는 true를 반환합니다.

예제

다음 예제는 Equals 메서드.

// 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)
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)
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
End Class
'
'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
'

설명

이 메서드는 서 수 (대/소문자 구분 및 문화권을 구분 하지 않는) 비교를 수행 합니다.

추가 정보

  • CompareOrdinal(String, String)

적용 대상

Equals(String, String, StringComparison)

지정된 두 String 개체의 값이 같은지를 확인합니다. 매개 변수는 비교에 사용되는 문화권, 대/소문자 및 정렬 규칙을 지정합니다.

public:
 static bool Equals(System::String ^ a, System::String ^ b, StringComparison comparisonType);
public static bool Equals (string a, string b, StringComparison comparisonType);
public static bool Equals (string? a, string? b, StringComparison comparisonType);
static member Equals : string * string * StringComparison -> bool
Public Shared Function Equals (a As String, b As String, comparisonType As StringComparison) As Boolean

매개 변수

a String

비교할 첫 번째 문자열 또는 null입니다.

b String

비교할 두 번째 문자열 또는 null입니다.

반환

Boolean

true 매개 변수와 a 매개 변수의 값이 같으면 b이고, 그러지 않으면 false입니다.

예외

예제

다음 예제에서는 열거형의 각 멤버를 사용 하 여 4 개의 단어 집합을 비교 합니다 StringComparison . 비교에서는 영어 (미국) 및 라프어 (Upper 스웨덴) 문화권의 규칙을 사용 합니다. 문자열 "encyclopædia" 및 "encyclopaedia"는 en-us 문화권에서 동일 하 게 간주 되지만 Sami (북부 스웨덴) 문화권이 아닌 것으로 간주 됩니다.

using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      String[] cultureNames = { "en-US", "se-SE" };
      String[] strings1 = { "case",  "encyclopædia",  
                            "encyclopædia", "Archæology" };
      String[] strings2 = { "Case", "encyclopaedia", 
                            "encyclopedia" , "ARCHÆOLOGY" };
      StringComparison[] comparisons = (StringComparison[]) Enum.GetValues(typeof(StringComparison));
      
      foreach (var cultureName in cultureNames) {
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
         Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
         for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++) {
            foreach (var comparison in comparisons) 
               Console.WriteLine("   {0} = {1} ({2}): {3}", strings1[ctr],
                                 strings2[ctr], comparison, 
                                 String.Equals(strings1[ctr], strings2[ctr], comparison));

            Console.WriteLine();         
         }
         Console.WriteLine();
      }
   }
}
// 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
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

설명

comparisonType매개 변수는 비교 시 현재 또는 고정 문화권을 사용 해야 하는지 여부를 지정 하 고 비교 하는 두 문자열의 대/소문자를 그대로 사용 하거나 무시 하거나 단어 또는 서 수 정렬 규칙을 사용 합니다.

추가 정보

  • CompareOrdinal(String, String)

적용 대상

Equals(Object)

이 인스턴스와 지정한 개체의 값이 같은지를 확인합니다. 이 개체도 String 개체여야 합니다.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

매개 변수

obj Object

이 인스턴스와 비교할 문자열입니다.

반환

Boolean

trueobj이고 이 인스턴스와 같은 값을 가지면 String이고, 그러지 않으면 false입니다. objnull이면 메서드에서 false을 반환합니다.

예제

다음 예제는 Equals 메서드.

// 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)
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)
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
End Class
'
'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
'

설명

이 메서드는 서 수 (대/소문자 구분 및 문화권을 구분 하지 않는) 비교를 수행 합니다.

추가 정보

  • Object
  • CompareOrdinal(String, String)

적용 대상

Equals(String)

이 인스턴스와 지정한 다른 String 개체의 값이 같은지를 확인합니다.

public:
 virtual bool Equals(System::String ^ value);
public:
 bool Equals(System::String ^ value);
public bool Equals (string value);
public bool Equals (string? value);
override this.Equals : string -> bool
Public Function Equals (value As String) As Boolean

매개 변수

value String

이 인스턴스와 비교할 문자열입니다.

반환

Boolean

true 매개 변수와 이 인스턴스의 값이 같으면 value이고, 그러지 않으면 false입니다. valuenull이면 메서드에서 false을 반환합니다.

구현

예제

다음 예제는 Equals 메서드. 이는 제목 대/소문자 단어 "File"과 해당 단어, 소문자, 대문자 및 라틴어 소문자 I (U + 0069) 대신 라틴어 소문자 점 (u + 0131)을 포함 하는 단어를 비교 합니다. Equals(String)이 메서드는 서 수 비교를 수행 하기 때문에 동일한 단어가 포함 된 비교만 반환 true 합니다.

using System;

public class Example
{
   public static void Main()
   {
      Console.OutputEncoding = System.Text.Encoding.UTF8;
      string word = "File";
      string[] others = { word.ToLower(), word, word.ToUpper(), "Fıle" };
      foreach (string other in others)
      {
         if (word.Equals(other)) 
            Console.WriteLine("{0} = {1}", word, other);
         else
            Console.WriteLine("{0} {1} {2}", word, '\u2260', other);
      }        
   }
}
// The example displays the following output:
//       File ≠ file
//       File = File
//       File ≠ FILE
//       File ≠ Fıle
Module Example
   Public Sub Main()
      Console.OutputEncoding = System.Text.Encoding.UTF8
      
      Dim word As String = "File"
      Dim others() As String = { word.ToLower(), word, word.ToUpper(), _
                                 "Fıle" }
      For Each other As String In others
         If word.Equals(other) Then 
            Console.WriteLine("{0} = {1}", word, other)
         Else
            Console.WriteLine("{0} {1} {2}", word, ChrW(&H2260), other)
         End If      
      Next        
   End Sub
End Module
' The example displays the following output:
'       File ≠ file
'       File = File
'       File ≠ FILE
'       File ≠ Fıle

설명

이 메서드는 서 수 (대/소문자 구분 및 문화권을 구분 하지 않는) 비교를 수행 합니다.

추가 정보

  • CompareOrdinal(String, String)

적용 대상