String.EndsWith String.EndsWith String.EndsWith String.EndsWith Method

정의

이 문자열 인스턴스의 끝 부분과 지정한 문자열이 일치하는지를 확인합니다.Determines whether the end of this string instance matches a specified string.

오버로드

EndsWith(Char) EndsWith(Char) EndsWith(Char) EndsWith(Char)
EndsWith(String) EndsWith(String) EndsWith(String) EndsWith(String)

이 문자열 인스턴스의 끝 부분과 지정한 문자열이 일치하는지를 확인합니다.Determines whether the end of this string instance matches the specified string.

EndsWith(String, StringComparison) EndsWith(String, StringComparison) EndsWith(String, StringComparison) EndsWith(String, StringComparison)

지정한 비교 옵션을 사용하여 비교할 때 지정한 문자열과 이 문자열 인스턴스의 끝 부분이 일치하는지를 확인합니다.Determines whether the end of this string instance matches the specified string when compared using the specified comparison option.

EndsWith(String, Boolean, CultureInfo) EndsWith(String, Boolean, CultureInfo) EndsWith(String, Boolean, CultureInfo) EndsWith(String, Boolean, CultureInfo)

지정한 문화권을 사용하여 비교할 때 이 문자열 인스턴스의 끝 부분과 지정한 문자열이 일치하는지를 확인합니다.Determines whether the end of this string instance matches the specified string when compared using the specified culture.

EndsWith(Char) EndsWith(Char) EndsWith(Char) EndsWith(Char)

public:
 bool EndsWith(char value);
public bool EndsWith (char value);
member this.EndsWith : char -> bool
Public Function EndsWith (value As Char) As Boolean

매개 변수

value
Char Char Char Char

반환

EndsWith(String) EndsWith(String) EndsWith(String) EndsWith(String)

이 문자열 인스턴스의 끝 부분과 지정한 문자열이 일치하는지를 확인합니다.Determines whether the end of this string instance matches the specified string.

public:
 bool EndsWith(System::String ^ value);
public bool EndsWith (string value);
member this.EndsWith : string -> bool
Public Function EndsWith (value As String) As Boolean

매개 변수

value
String String String String

이 인스턴스의 끝 부분에 있는 부분 문자열과 비교할 문자열입니다.The string to compare to the substring at the end of this instance.

반환

이 인스턴스의 끝이 true와 일치하면 value이고, 그러지 않으면 false입니다.true if value matches the end of this instance; otherwise, false.

예외

예제

다음 예제에서는 배열의 각 문자열을 기간으로 끝나는지 여부를 나타냅니다 (".").The following example indicates whether each string in an array ends with a period (".").

using System;

public class Example
{
   public static void Main()
   {
      String[] strings = { "This is a string.", "Hello!", "Nothing.", 
                           "Yes.", "randomize" };
      foreach (var value in strings) {
         bool endsInPeriod = value.EndsWith(".");
         Console.WriteLine("'{0}' ends in a period: {1}", 
                           value, endsInPeriod);
      }                            
   }
}
// The example displays the following output:
//       'This is a string.' ends in a period: True
//       'Hello!' ends in a period: False
//       'Nothing.' ends in a period: True
//       'Yes.' ends in a period: True
//       'randomize' ends in a period: False
Module Example
   Public Sub Main()
      Dim strings() As String = { "This is a string.", "Hello!", 
                                  "Nothing.", "Yes.", "randomize" }
      For Each value In strings
         Dim endsInPeriod As Boolean = value.EndsWith(".")
         Console.WriteLine("'{0}' ends in a period: {1}", 
                           value, endsInPeriod)
      Next                            
   End Sub
End Module
' The example displays the following output:
'       'This is a string.' ends in a period: True
'       'Hello!' ends in a period: False
'       'Nothing.' ends in a period: True
'       'Yes.' ends in a period: True
'       'randomize' ends in a period: False

다음 예제에서는 정의 StripEndTags 메서드를 사용 하는 EndsWith(String) 줄의 끝에서 끝 태그를 HTML을 제거 하는 방법입니다.The following example defines a StripEndTags method that uses the EndsWith(String) method to remove HTML end tags from the end of a line. StripEndTags 줄의 끝에 여러 HTML 끝 태그가 제거 되도록에 재귀적으로 호출 됩니다.Note that the StripEndTags method is called recursively to ensure that multiple HTML end tags at the end of the line are removed.

using namespace System;
using namespace System::Collections;

String^ StripEndTags( String^ item )
{
   bool found = false;
   
   // try to find a tag at the end of the line using EndsWith
   if ( item->Trim()->EndsWith( ">" ) )
   {
      
      // now search for the opening tag...
      int lastLocation = item->LastIndexOf( "</" );
      
      // remove the identified section, if it is a valid region
      if ( lastLocation >= 0 ) {
            item = item->Substring( 0, lastLocation );
            found = true;
      }
   }

   if (found) item = StripEndTags(item);
   
   return item;
}

int main()
{
   
   // process an input file that contains html tags.
   // this sample checks for multiple tags at the end of the line, rather than simply
   // removing the last one.
   // note: HTML markup tags always end in a greater than symbol (>).
   array<String^>^strSource = {"<b>This is bold text</b>","<H1>This is large Text</H1>","<b><i><font color=green>This has multiple tags</font></i></b>","<b>This has <i>embedded</i> tags.</b>","This line simply ends with a greater than symbol, it should not be modified>"};
   Console::WriteLine( "The following lists the items before the ends have been stripped:" );
   Console::WriteLine( "-----------------------------------------------------------------" );
   
   // print out the initial array of strings
   IEnumerator^ myEnum1 = strSource->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum1->Current);
      Console::WriteLine( s );
   }

   Console::WriteLine();
   Console::WriteLine( "The following lists the items after the ends have been stripped:" );
   Console::WriteLine( "----------------------------------------------------------------" );
   
   // Display the array of strings.
   IEnumerator^ myEnum2 = strSource->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum2->Current);
      Console::WriteLine( StripEndTags( s ) );
   }
}
// The example displays the following output:
//    The following lists the items before the ends have been stripped:
//    -----------------------------------------------------------------
//    <b>This is bold text</b>
//    <H1>This is large Text</H1>
//    <b><i><font color=green>This has multiple tags</font></i></b>
//    <b>This has <i>embedded</i> tags.</b>
//    This line simply ends with a greater than symbol, it should not be modified>
//    
//    The following lists the items after the ends have been stripped:
//    ----------------------------------------------------------------
//    <b>This is bold text
//    <H1>This is large Text
//    <b><i><font color=green>This has multiple tags
//    <b>This has <i>embedded</i> tags.
//    This line simply ends with a greater than symbol, it should not be modified>
using System;

public class EndsWithTest {
    public static void Main() {

        // process an input file that contains html tags.
        // this sample checks for multiple tags at the end of the line, rather than simply
        // removing the last one.
        // note: HTML markup tags always end in a greater than symbol (>).

        string [] strSource = { "<b>This is bold text</b>", "<H1>This is large Text</H1>",
                "<b><i><font color=green>This has multiple tags</font></i></b>",
                "<b>This has <i>embedded</i> tags.</b>",
                "This line simply ends with a greater than symbol, it should not be modified>" };

        Console.WriteLine("The following lists the items before the ends have been stripped:");
        Console.WriteLine("-----------------------------------------------------------------");

        // print out the initial array of strings
        foreach ( string s in strSource )
            Console.WriteLine( s );

        Console.WriteLine();

        Console.WriteLine("The following lists the items after the ends have been stripped:");
        Console.WriteLine("----------------------------------------------------------------");

        // print out the array of strings
        foreach (var s in strSource)
            Console.WriteLine(StripEndTags(s));
    }

    private static string StripEndTags( string item ) {

        bool found = false;
            
        // try to find a tag at the end of the line using EndsWith
        if (item.Trim().EndsWith(">")) {
                
            // now search for the opening tag...
            int lastLocation = item.LastIndexOf( "</" );

            // remove the identified section, if it is a valid region
            if ( lastLocation >= 0 ) {
                found = true;
                item =  item.Substring( 0, lastLocation );
            }    
        }

        if (found)
           item = StripEndTags(item);
           
        return item;
    }
}
// The example displays the following output:
//    The following lists the items before the ends have been stripped:
//    -----------------------------------------------------------------
//    <b>This is bold text</b>
//    <H1>This is large Text</H1>
//    <b><i><font color=green>This has multiple tags</font></i></b>
//    <b>This has <i>embedded</i> tags.</b>
//    This line simply ends with a greater than symbol, it should not be modified>
//    
//    The following lists the items after the ends have been stripped:
//    ----------------------------------------------------------------
//    <b>This is bold text
//    <H1>This is large Text
//    <b><i><font color=green>This has multiple tags
//    <b>This has <i>embedded</i> tags.
//    This line simply ends with a greater than symbol, it should not be modified>
Public Module Example
    Public Sub Main()
        Dim strSource() As String = { "<b>This is bold text</b>", 
                    "<H1>This is large Text</H1>", 
                    "<b><i><font color = green>This has multiple tags</font></i></b>", 
                    "<b>This has <i>embedded</i> tags.</b>", 
                    "This line simply ends with a greater than symbol, it should not be modified>" }

        Console.WriteLine("The following lists the items before the ends have been stripped:")
        Console.WriteLine("-----------------------------------------------------------------")

        ' Display the initial array of strings.
        For Each s As String In  strSource
            Console.WriteLine(s)
        Next
        Console.WriteLine()

        Console.WriteLine("The following lists the items after the ends have been stripped:")
        Console.WriteLine("----------------------------------------------------------------")

        ' Display the array of strings.
        For Each s As String In strSource
            Console.WriteLine(StripEndTags(s))
        Next 
    End Sub 

    Private Function StripEndTags(item As String) As String
        Dim found As Boolean = False
        
        ' Try to find a tag at the end of the line using EndsWith.
        If item.Trim().EndsWith(">") Then
            ' now search for the opening tag...
            Dim lastLocation As Integer = item.LastIndexOf("</")
            If lastLocation >= 0 Then
                found = True
                
                ' Remove the identified section, if it is a valid region.
                item = item.Substring(0, lastLocation)
            End If
        End If
        
        If found Then item = StripEndTags(item)
        Return item
    End Function 
End Module
' The example displays the following output:
'    The following lists the items before the ends have been stripped:
'    -----------------------------------------------------------------
'    <b>This is bold text</b>
'    <H1>This is large Text</H1>
'    <b><i><font color = green>This has multiple tags</font></i></b>
'    <b>This has <i>embedded</i> tags.</b>
'    This line simply ends with a greater than symbol, it should not be modified>
'    
'    The following lists the items after the ends have been stripped:
'    ----------------------------------------------------------------
'    <b>This is bold text
'    <H1>This is large Text
'    <b><i><font color = green>This has multiple tags
'    <b>This has <i>embedded</i> tags.
'    This line simply ends with a greater than symbol, it should not be modified>

설명

이 메서드는 비교 value 와 같은 길이이 인스턴스의 끝에 있는 부분 문자열과 value와 같은지 여부를 나타내는 값을 반환 합니다.This method compares value to the substring at the end of this instance that is the same length as value, and returns an indication whether they are equal. 같은 문자로 value 이 동일한 인스턴스에 대 한 참조 이거나이 인스턴스의 끝 부분과 일치 해야 합니다.To be equal, value must be a reference to this same instance or match the end of this instance.

이 메서드는 현재 문화권을 사용 하 여 단어 (대/소문자 구분 및 문화권) 비교를 수행 합니다.This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture.

호출자 참고

에 설명 된 대로 를 사용 하 여 문자열에 대 한 모범 사례, 기본 값으로 대체 하 고 대신 매개 변수를 명시적으로 지정 해야 하는 메서드를 호출 하는 문자열 비교 메서드를 호출 하지 않는 것이 좋습니다.As explained in Best Practices for Using Strings, we recommend that you avoid calling string comparison methods that substitute default values and instead call methods that require parameters to be explicitly specified. 현재 문화권의 문자열 비교 규칙을 사용 하 여 특정 문자열이 부분 문자열로 끝나는지 여부를 결정할 호출을 EndsWith(String, StringComparison) 값을 사용 하 여 메서드 오버 로드 CurrentCulture 에 대 한 해당 comparisonType 매개 변수입니다.To determine whether a string ends with a particular substring by using the string comparison rules of the current culture, call the EndsWith(String, StringComparison) method overload with a value of CurrentCulture for its comparisonType parameter.

추가 정보

EndsWith(String, StringComparison) EndsWith(String, StringComparison) EndsWith(String, StringComparison) EndsWith(String, StringComparison)

지정한 비교 옵션을 사용하여 비교할 때 지정한 문자열과 이 문자열 인스턴스의 끝 부분이 일치하는지를 확인합니다.Determines whether the end of this string instance matches the specified string when compared using the specified comparison option.

public:
 bool EndsWith(System::String ^ value, StringComparison comparisonType);
[System.Runtime.InteropServices.ComVisible(false)]
public bool EndsWith (string value, StringComparison comparisonType);
member this.EndsWith : string * StringComparison -> bool
Public Function EndsWith (value As String, comparisonType As StringComparison) As Boolean

매개 변수

value
String String String String

이 인스턴스의 끝 부분에 있는 부분 문자열과 비교할 문자열입니다.The string to compare to the substring at the end of this instance.

comparisonType
StringComparison StringComparison StringComparison StringComparison

이 문자열과 value를 비교하는 방법을 결정하는 열거형 값 중 하나입니다.One of the enumeration values that determines how this string and value are compared.

반환

이 문자열의 끝이 value 매개 변수와 일치하면 true이고, 그러지 않으면 false입니다.true if the value parameter matches the end of this string; otherwise, false.

예외

comparisonTypeStringComparison 값이 아닙니다.comparisonType is not a StringComparison value.

예제

다음 예제에서는 특정 하위 문자열로 끝나는지 여부를 결정 합니다.The following example determines whether a string ends with a particular substring. 문화권, 대/소문자가 무시 여부 및 서 수 비교를 수행 하는 지 여부를 선택 하면 영향을 받습니다.The results are affected by the choice of culture, whether case is ignored, and whether an ordinal comparison is performed.

// This example demonstrates the 
// System.String.EndsWith(String, StringComparison) method.

using namespace System;
using namespace System::Threading;

void Test(String^ testString, String^ searchString, 
     StringComparison comparison)
{
    String^ resultFormat = "\"{0}\" {1} with \"{2}\".";
    String^ resultString = "does not end";

    if (testString->EndsWith(searchString, comparison))
    {
        resultString = "ends";
    }
    Console::WriteLine(resultFormat, testString, resultString, searchString);
}

int main()
{
    String^ introMessage =
        "Determine whether a string ends with another string, " +
        "using\ndifferent values of StringComparison.";

    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);
    // Perform two tests for each StringComparison
    for each (StringComparison stringCmp in comparisonValues)
    {
        Console::WriteLine("StringComparison.{0}:", stringCmp);
        Test("abcXYZ", "XYZ", stringCmp);
        Test("abcXYZ", "xyz", stringCmp);
        Console::WriteLine();
    }
}

/*
This code example produces the following results:

Determine whether a string ends with another string, using
different values of StringComparison.
The current culture is en-US.

StringComparison.CurrentCulture:
"abcXYZ" ends with "XYZ".
"abcXYZ" does not end with "xyz".

StringComparison.CurrentCultureIgnoreCase:
"abcXYZ" ends with "XYZ".
"abcXYZ" ends with "xyz".

StringComparison.InvariantCulture:
"abcXYZ" ends with "XYZ".
"abcXYZ" does not end with "xyz".

StringComparison.InvariantCultureIgnoreCase:
"abcXYZ" ends with "XYZ".
"abcXYZ" ends with "xyz".

StringComparison.Ordinal:
"abcXYZ" ends with "XYZ".
"abcXYZ" does not end with "xyz".

StringComparison.OrdinalIgnoreCase:
"abcXYZ" ends with "XYZ".
"abcXYZ" ends with "xyz".

*/
// This example demonstrates the 
// System.String.EndsWith(String, StringComparison) method.

using System;
using System.Threading;

class Sample 
{
    public static void Main() 
    {
    string intro = "Determine whether a string ends with another string, " +
                   "using\n  different values of StringComparison.";

    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);
        Test("abcXYZ", "XYZ", sc);
        Test("abcXYZ", "xyz", sc);
        Console.WriteLine();
        }
    }

    protected static void Test(string x, string y, StringComparison comparison)
    {
    string resultFmt = "\"{0}\" {1} with \"{2}\".";
    string result = "does not end";
//
    if (x.EndsWith(y, comparison))
        result = "ends";
    Console.WriteLine(resultFmt, x, result, y);
    }
}

/*
This code example produces the following results:

Determine whether a string ends with another string, using
  different values of StringComparison.
The current culture is en-US.

StringComparison.CurrentCulture:
"abcXYZ" ends with "XYZ".
"abcXYZ" does not end with "xyz".

StringComparison.CurrentCultureIgnoreCase:
"abcXYZ" ends with "XYZ".
"abcXYZ" ends with "xyz".

StringComparison.InvariantCulture:
"abcXYZ" ends with "XYZ".
"abcXYZ" does not end with "xyz".

StringComparison.InvariantCultureIgnoreCase:
"abcXYZ" ends with "XYZ".
"abcXYZ" ends with "xyz".

StringComparison.Ordinal:
"abcXYZ" ends with "XYZ".
"abcXYZ" does not end with "xyz".

StringComparison.OrdinalIgnoreCase:
"abcXYZ" ends with "XYZ".
"abcXYZ" ends with "xyz".

*/
' This example demonstrates the 
' System.String.EndsWith(String, StringComparison) method.

Imports System.Threading

Class Sample
    Public Shared Sub Main() 
        Dim intro As String = "Determine whether a string ends with another string, " & _
                              "using" & vbCrLf & "  different values of StringComparison."
        
        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)
            Test("abcXYZ", "XYZ", sc)
            Test("abcXYZ", "xyz", sc)
            Console.WriteLine()
        Next sc
    
    End Sub 'Main
    
    
    Protected Shared Sub Test(ByVal x As String, ByVal y As String, _
                              ByVal comparison As StringComparison) 
        Dim resultFmt As String = """{0}"" {1} with ""{2}""."
        Dim result As String = "does not end"
        '
        If x.EndsWith(y, comparison) Then
            result = "ends"
        End If
        Console.WriteLine(resultFmt, x, result, y)
    
    End Sub 'Test
End Class 'Sample

'
'This code example produces the following results:
'
'Determine whether a string ends with another string, using
'  different values of StringComparison.
'The current culture is en-US.
'
'StringComparison.CurrentCulture:
'"abcXYZ" ends with "XYZ".
'"abcXYZ" does not end with "xyz".
'
'StringComparison.CurrentCultureIgnoreCase:
'"abcXYZ" ends with "XYZ".
'"abcXYZ" ends with "xyz".
'
'StringComparison.InvariantCulture:
'"abcXYZ" ends with "XYZ".
'"abcXYZ" does not end with "xyz".
'
'StringComparison.InvariantCultureIgnoreCase:
'"abcXYZ" ends with "XYZ".
'"abcXYZ" ends with "xyz".
'
'StringComparison.Ordinal:
'"abcXYZ" ends with "XYZ".
'"abcXYZ" does not end with "xyz".
'
'StringComparison.OrdinalIgnoreCase:
'"abcXYZ" ends with "XYZ".
'"abcXYZ" ends with "xyz".
'

설명

합니다 EndsWith 메서드 비교는 value 이 문자열의 끝에 있는 부분 문자열과 매개 변수 같은지 여부를 나타내는 값을 반환 합니다.The EndsWith method compares the value parameter to the substring at the end of this string and returns a value that indicates whether they are equal. 같은 문자로 value 이 동일한 문자열에 대 한 참조를 여야 하며, 빈 문자열 이어야 합니다 (""), 또는이 문자열의 끝과 일치 해야 합니다.To be equal, value must be a reference to this same string, must be the empty string (""), or must match the end of this string. 수행할 비교 유형을 합니다 EndsWith 메서드 값에 따라 달라 집니다는 comparisonType 매개 변수입니다.The type of comparison performed by the EndsWith method depends on the value of the comparisonType parameter.

추가 정보

EndsWith(String, Boolean, CultureInfo) EndsWith(String, Boolean, CultureInfo) EndsWith(String, Boolean, CultureInfo) EndsWith(String, Boolean, CultureInfo)

지정한 문화권을 사용하여 비교할 때 이 문자열 인스턴스의 끝 부분과 지정한 문자열이 일치하는지를 확인합니다.Determines whether the end of this string instance matches the specified string when compared using the specified culture.

public:
 bool EndsWith(System::String ^ value, bool ignoreCase, System::Globalization::CultureInfo ^ culture);
public bool EndsWith (string value, bool ignoreCase, System.Globalization.CultureInfo culture);
member this.EndsWith : string * bool * System.Globalization.CultureInfo -> bool
Public Function EndsWith (value As String, ignoreCase As Boolean, culture As CultureInfo) As Boolean

매개 변수

value
String String String String

이 인스턴스의 끝 부분에 있는 부분 문자열과 비교할 문자열입니다.The string to compare to the substring at the end of this instance.

ignoreCase
Boolean Boolean Boolean Boolean

비교 시 대/소문자를 무시하려면 true이고, 그러지 않으면 false입니다.true to ignore case during the comparison; otherwise, false.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

이 인스턴스와 value의 비교 방법을 결정하는 문화권 정보입니다.Cultural information that determines how this instance and value are compared. culturenull이면 현재 문화권이 사용됩니다.If culture is null, the current culture is used.

반환

이 문자열의 끝이 value 매개 변수와 일치하면 true이고, 그러지 않으면 false입니다.true if the value parameter matches the end of this string; otherwise, false.

예외

예제

다음 예제에서는 문자열을 다른 문자열의 끝에서 발생 하는지 여부를 결정 합니다.The following example determines whether a string occurs at the end of another string. EndsWith 메서드가 여러 번 대/소문자 구분, 소문자, 및 검색 결과 영향을 주는 다른 문화권을 사용 하 여 호출 됩니다.The EndsWith method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search.

// This code example demonstrates the 
// System.String.EndsWith(String, ..., CultureInfo) method.

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

class Sample 
{
    public static void Main() 
    {
    string msg1 = "Search for the target string \"{0}\" in the string \"{1}\".\n";
    string msg2 = "Using the {0} - \"{1}\" culture:";
    string msg3 = "  The string to search ends with the target string: {0}";
    bool result = false;
    CultureInfo ci;

// Define a target string to search for.
// U+00c5 = LATIN CAPITAL LETTER A WITH RING ABOVE
    string capitalARing = "\u00c5";

// Define a string to search. 
// The result of combining the characters LATIN SMALL LETTER A and COMBINING 
// RING ABOVE (U+0061, U+030a) is linguistically equivalent to the character 
// LATIN SMALL LETTER A WITH RING ABOVE (U+00e5).
    string xyzARing = "xyz" + "\u0061\u030a";

// Clear the screen and display an introduction.
    Console.Clear();

// Display the string to search for and the string to search.
    Console.WriteLine(msg1, capitalARing, xyzARing);

// Search using English-United States culture.
    ci = new CultureInfo("en-US");
    Console.WriteLine(msg2, ci.DisplayName, ci.Name);

    Console.WriteLine("Case sensitive:");
    result = xyzARing.EndsWith(capitalARing, false, ci);
    Console.WriteLine(msg3, result);

    Console.WriteLine("Case insensitive:");
    result = xyzARing.EndsWith(capitalARing, true, ci);
    Console.WriteLine(msg3, result);
    Console.WriteLine();

// Search using Swedish-Sweden culture.
    ci = new CultureInfo("sv-SE");
    Console.WriteLine(msg2, ci.DisplayName, ci.Name);

    Console.WriteLine("Case sensitive:");
    result = xyzARing.EndsWith(capitalARing, false, ci);
    Console.WriteLine(msg3, result);

    Console.WriteLine("Case insensitive:");
    result = xyzARing.EndsWith(capitalARing, true, ci);
    Console.WriteLine(msg3, result);
    }
}

/*
Note: This code example was executed on a console whose user interface 
culture is "en-US" (English-United States).

This code example produces the following results:

Search for the target string "Å" in the string "xyza°".

Using the English (United States) - "en-US" culture:
Case sensitive:
  The string to search ends with the target string: False
Case insensitive:
  The string to search ends with the target string: True

Using the Swedish (Sweden) - "sv-SE" culture:
Case sensitive:
  The string to search ends with the target string: False
Case insensitive:
  The string to search ends with the target string: False

*/
' This code example demonstrates the 
' System.String.EndsWith(String, ..., CultureInfo) method.

Imports System.Threading
Imports System.Globalization

Class Sample
    Public Shared Sub Main() 
        Dim msg1 As String = "Search for the target string ""{0}"" in the string ""{1}""." & vbCrLf
        Dim msg2 As String = "Using the {0} - ""{1}"" culture:"
        Dim msg3 As String = "  The string to search ends with the target string: {0}"
        Dim result As Boolean = False
        Dim ci As CultureInfo
        
        ' Define a target string to search for.
        ' U+00c5 = LATIN CAPITAL LETTER A WITH RING ABOVE
        Dim capitalARing As String = "Å"
        
        ' Define a string to search. 
        ' The result of combining the characters LATIN SMALL LETTER A and COMBINING 
        ' RING ABOVE (U+0061, U+030a) is linguistically equivalent to the character 
        ' LATIN SMALL LETTER A WITH RING ABOVE (U+00e5).
        Dim xyzARing As String = "xyz" & "å"
        
        ' Clear the screen and display an introduction.
        Console.Clear()
        
        ' Display the string to search for and the string to search.
        Console.WriteLine(msg1, capitalARing, xyzARing)
        
        ' Search using English-United States culture.
        ci = New CultureInfo("en-US")
        Console.WriteLine(msg2, ci.DisplayName, ci.Name)
        
        Console.WriteLine("Case sensitive:")
        result = xyzARing.EndsWith(capitalARing, False, ci)
        Console.WriteLine(msg3, result)
        
        Console.WriteLine("Case insensitive:")
        result = xyzARing.EndsWith(capitalARing, True, ci)
        Console.WriteLine(msg3, result)
        Console.WriteLine()
        
        ' Search using Swedish-Sweden culture.
        ci = New CultureInfo("sv-SE")
        Console.WriteLine(msg2, ci.DisplayName, ci.Name)
        
        Console.WriteLine("Case sensitive:")
        result = xyzARing.EndsWith(capitalARing, False, ci)
        Console.WriteLine(msg3, result)
        
        Console.WriteLine("Case insensitive:")
        result = xyzARing.EndsWith(capitalARing, True, ci)
        Console.WriteLine(msg3, result)
    
    End Sub 'Main
End Class 'Sample

'
'Note: This code example was executed on a console whose user interface 
'culture is "en-US" (English-United States).
'
'This code example produces the following results:
'
'Search for the target string "Å" in the string "xyza°".
'
'Using the English (United States) - "en-US" culture:
'Case sensitive:
'  The string to search ends with the target string: False
'Case insensitive:
'  The string to search ends with the target string: True
'
'Using the Swedish (Sweden) - "sv-SE" culture:
'Case sensitive:
'  The string to search ends with the target string: False
'Case insensitive:
'  The string to search ends with the target string: False
'

설명

이 메서드를 비교 합니다 value 와 같은 길이이 문자열의 끝에 있는 부분 문자열과 매개 변수 value, 같은지 여부를 나타내는 값을 반환 합니다.This method compares the value parameter to the substring at the end of this string that is the same length as value, and returns a value that indicates whether they are equal. 같은 문자로 value 이 동일한 인스턴스에 대 한 참조 하거나이 문자열의 끝과 일치 해야 합니다.To be equal, value must be a reference to this same instance or match the end of this string.

이 메서드는 지정 된 대/소문자 구분 및 문화권을 사용 하 여 단어 (문화권별) 비교를 수행 합니다.This method performs a word (culture-sensitive) comparison using the specified casing and culture.

추가 정보

적용 대상