CompareInfo.LastIndexOf 메서드

정의

문자열 전체나 일부에서 마지막에 나오는 값의 인덱스(0부터 시작)를 반환합니다.

오버로드

LastIndexOf(String, String, Int32, Int32, CompareOptions)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 CompareOptions 값을 사용하여 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, Char, Int32, Int32, CompareOptions)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 CompareOptions 값을 사용하여 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, String, Int32, Int32)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, String, Int32, CompareOptions)

소스 문자열 중 문자열의 시작 부분부터 지정된 인덱스까지의 영역에서 지정된 CompareOptions 값을 사용하여 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, Char, Int32, Int32)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, Char, Int32, CompareOptions)

소스 문자열 중 문자열의 시작 부분부터 지정된 인덱스까지의 영역에서 지정된 CompareOptions 값을 사용하여 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

소스 문자열에서 마지막에 나타나는 부분 문자열을 검색합니다.

LastIndexOf(String, Char)

전체 소스 문자열에서 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, String, CompareOptions)

전체 소스 문자열에서 지정된 CompareOptions 값을 사용하여 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, Char, Int32)

소스 문자열 중 처음부터 지정된 인덱스까지의 영역에서 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, Char, CompareOptions)

전체 소스 문자열에서 지정된 CompareOptions 값을 사용하여 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

지정된 읽기 전용 문자 범위 내에서 마지막 Rune을 검색합니다.

LastIndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

지정된 읽기 전용 문자 범위 내에서 마지막 하위 문자열을 검색합니다.

LastIndexOf(String, String)

전체 소스 문자열에서 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, String, Int32)

소스 문자열 중 처음부터 지정된 인덱스까지의 영역에서 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

LastIndexOf(String, String, Int32, Int32, CompareOptions)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 CompareOptions 값을 사용하여 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex, int count, System::Globalization::CompareOptions options);
public:
 int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex, int count, System::Globalization::CompareOptions options);
public virtual int LastIndexOf (string source, string value, int startIndex, int count, System.Globalization.CompareOptions options);
public int LastIndexOf (string source, string value, int startIndex, int count, System.Globalization.CompareOptions options);
abstract member LastIndexOf : string * string * int * int * System.Globalization.CompareOptions -> int
override this.LastIndexOf : string * string * int * int * System.Globalization.CompareOptions -> int
member this.LastIndexOf : string * string * int * int * System.Globalization.CompareOptions -> int
Public Overridable Function LastIndexOf (source As String, value As String, startIndex As Integer, count As Integer, options As CompareOptions) As Integer
Public Function LastIndexOf (source As String, value As String, startIndex As Integer, count As Integer, options As CompareOptions) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
String

source에서 찾을 문자열입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

count
Int32

검색할 섹션에 있는 요소 수입니다.

options
CompareOptions

sourcevalue을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

Int32

valuesource로 지정된 수의 요소를 포함하고 count에서 끝나는 영역에서 지정된 비교 옵션을 사용하여 startIndex를 찾은 경우 맨 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

또는

value이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

또는

count가 0보다 작은 경우

또는

startIndexcountsource의 올바른 섹션을 지정하지 않습니다.

options에 잘못된 CompareOptions 값이 포함된 경우

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 8;
   
   // iL is the length of the substring.
   int iL = 18;
   
   // myT1 and myT2 are the strings used for padding.
   String^ myT1 = gcnew String( '-',iS );
   String^ myT2;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 8;
      // iL is the length of the substring.
      int iL = 18;
      // myT1 and myT2 are the strings used for padding.
      String myT1 = new String( '-', iS );
      String myT2;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 8
      ' iL is the length of the substring.
      Dim iL As Integer = 18
      ' myT1 and myT2 are the strings used for padding.
      Dim myT1 As New [String]("-"c, [iS])
      Dim myT2 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------- ae the same as Æ -----
'           AE :                         b
'           ae :          b
'            Æ :                         b
'            æ :          b
'Ordinal       : -------- ae the same as Æ -----
'           AE :
'           ae :          b
'            Æ :                         b
'            æ :
'IgnoreCase    : -------- ae the same as Æ -----
'           AE :          f              l
'           ae :          f              l
'            Æ :          f              l
'            æ :          f              l
'
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------- u" the same as Ü -----
'           U" :                         b
'           u" :          b
'            Ü :                         b
'            ü :          b
'Ordinal       : -------- u" the same as Ü -----
'           U" :
'           u" :          b
'            Ü :                         b
'            ü :
'IgnoreCase    : -------- u" the same as Ü -----
'           U" :          f              l
'           u" :          f              l
'            Ü :          f              l
'            ü :          f              l

설명

원본 문자열은 +1부터 startIndex startIndex - count 시작하여 끝나는 뒤로 검색됩니다.

CompareOptions.StringSort 메서드에 대한 값이 잘못되었습니다.

options 값이 Ordinal 포함되지 않으면 이 오버로드는 문화권에 민감한 검색을 수행합니다. 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 값이 Ordinal 포함된 경우 options 이 오버로드는 유니코드 값이 비교되는 서수(문화권을 구분하지 않는) 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권 구분 검색(즉, optionsOrdinal 또는 OrdinalIgnoreCase가 아닌 경우)에서는 value에 무시할 수 있는 문자가 포함된 경우 결과는 해당 문자가 제거된 대상을 검색하는 것과 같습니다. 하나 이상의 무시 가능한 문자로만 구성된 경우 value 메서드는 LastIndexOf(String, String, Int32, Int32, CompareOptions) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다.

다음 예제 LastIndexOf(String, String, Int32, Int32, CompareOptions) 에서 메서드는 소프트 하이픈(U+00AD)의 위치를 찾은 다음 두 문자열의 마지막 "m" 앞에 있는 첫 번째 문자 위치를 제외한 모든 위치에서 "m"을 찾는 데 사용됩니다. 문자열 중 하나에만 필수 부분 문자열이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 메서드는 문화권 구분 비교를 수행할 때 문자열에서 "m"의 인덱스를 반환합니다. 그러나 서수 비교를 수행하는 경우 첫 번째 문자열에서만 부분 문자열을 찾습니다. 소프트 하이픈과 "m"을 포함하는 첫 번째 문자열의 경우 메서드는 소프트 하이픈의 인덱스를 반환하지 못하고 문화권 구분 비교를 수행할 때 "m"의 인덱스를 반환합니다. 메서드는 서수 비교를 수행하는 경우에만 첫 번째 문자열에서 사용자 지정 하이픈의 인덱스를 반환합니다.

Imports System.Globalization

Public Module Example
   Public Sub Main()
      Dim ci As CompareInfo = CultureInfo.CurrentCulture.CompareInfo

      Dim searchString As String = ChrW(&h00AD) + "m"
      Dim s1 As String = "ani" + ChrW(&h00AD) + "m" 
      Dim s2 As String = "animal"
      Dim position As Integer

      position = ci.LastIndexOf(s1, "m"c)
      If position >= 1 Then
         Console.WriteLine(ci.LastIndexOf(s1, searchString, position, position, CompareOptions.None))
         Console.WriteLine(ci.LastIndexOf(s1, searchString, position, position, CompareOptions.Ordinal))
      End If      
      
      position = ci.LastIndexOf(s2, "m"c)
      If position >= 1 Then 
         Console.WriteLine(ci.LastIndexOf(s2, searchString, position, position, CompareOptions.None))
         Console.WriteLine(ci.LastIndexOf(s2, searchString, position, position, CompareOptions.Ordinal))
      End If
   End Sub
End Module
' The example displays the following output:
'       4
'       3
'       3
'       -1

추가 정보

적용 대상

LastIndexOf(String, Char, Int32, Int32, CompareOptions)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 CompareOptions 값을 사용하여 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, char value, int startIndex, int count, System::Globalization::CompareOptions options);
public:
 int LastIndexOf(System::String ^ source, char value, int startIndex, int count, System::Globalization::CompareOptions options);
public virtual int LastIndexOf (string source, char value, int startIndex, int count, System.Globalization.CompareOptions options);
public int LastIndexOf (string source, char value, int startIndex, int count, System.Globalization.CompareOptions options);
abstract member LastIndexOf : string * char * int * int * System.Globalization.CompareOptions -> int
override this.LastIndexOf : string * char * int * int * System.Globalization.CompareOptions -> int
member this.LastIndexOf : string * char * int * int * System.Globalization.CompareOptions -> int
Public Overridable Function LastIndexOf (source As String, value As Char, startIndex As Integer, count As Integer, options As CompareOptions) As Integer
Public Function LastIndexOf (source As String, value As Char, startIndex As Integer, count As Integer, options As CompareOptions) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
Char

source에서 찾을 문자입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

count
Int32

검색할 섹션에 있는 요소 수입니다.

options
CompareOptions

sourcevalue을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

Int32

valuesource로 지정된 수의 요소를 포함하고 count에서 끝나는 영역에서 지정된 비교 옵션을 사용하여 startIndex를 찾은 경우 맨 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

또는

count가 0보다 작은 경우

또는

startIndexcountsource의 올바른 섹션을 지정하지 않습니다.

options에 잘못된 CompareOptions 값이 포함된 경우

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 8;
   
   // iL is the length of the substring.
   int iL = 18;
   
   // myT1 and myT2 are the strings used for padding.
   String^ myT1 = gcnew String( '-',iS );
   String^ myT2;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 8;
      // iL is the length of the substring.
      int iL = 18;
      // myT1 and myT2 are the strings used for padding.
      String myT1 = new String( '-', iS );
      String myT2;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 8
      ' iL is the length of the substring.
      Dim iL As Integer = 18
      ' myT1 and myT2 are the strings used for padding.
      Dim myT1 As New [String]("-"c, [iS])
      Dim myT2 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------- ae the same as Æ -----
'           AE :                         b
'           ae :          b
'            Æ :                         b
'            æ :          b
'Ordinal       : -------- ae the same as Æ -----
'           AE :
'           ae :          b
'            Æ :                         b
'            æ :
'IgnoreCase    : -------- ae the same as Æ -----
'           AE :          f              l
'           ae :          f              l
'            Æ :          f              l
'            æ :          f              l
'
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------- u" the same as Ü -----
'           U" :                         b
'           u" :          b
'            Ü :                         b
'            ü :          b
'Ordinal       : -------- u" the same as Ü -----
'           U" :
'           u" :          b
'            Ü :                         b
'            ü :
'IgnoreCase    : -------- u" the same as Ü -----
'           U" :          f              l
'           u" :          f              l
'            Ü :          f              l
'            ü :          f              l

설명

원본 문자열은 +1부터 startIndex startIndex - count 시작하여 끝나는 뒤로 검색됩니다.

CompareOptions.StringSort 메서드에 대한 값이 잘못되었습니다.

options 값이 Ordinal 포함되지 않으면 이 오버로드는 문화권에 민감한 검색을 수행합니다. 문자가 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값인 경우 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스의 구성 요소 발생과 동일한 것으로 간주될 수 있습니다. 값이 Ordinal 포함된 경우 options 이 오버로드는 서수(문화권을 구분하지 않는) 검색을 수행합니다. 문자는 유니코드 값이 동일한 경우에만 다른 문자와 동일한 것으로 간주됩니다. 해당 검색의 String.LastIndexOf 오버로드는 서수 검색을 수행하는 반면 문자열을 검색하는 오버로드는 문화권에 민감한 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권에 민감한 검색에서 무시할 수 있는 문자인 경우 value 결과는 해당 문자를 제거한 상태에서 검색하는 것과 같습니다. 이 경우 메서드는 LastIndexOf(String, Char, Int32, Int32, CompareOptions) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다. 다음 예제 LastIndexOf(String, Char, Int32, Int32, CompareOptions) 에서는 메서드를 사용하여 두 문자열의 마지막 "m" 앞에 오는 소프트 하이픈(U+00AD)을 찾습니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 문화권 구분 검색은 값인 "m" startIndex의 인덱스 위치를 반환합니다. 그러나 서수 검색은 한 문자열에서 소프트 하이픈을 찾은 후 두 번째 문자열에 없는 것을 보고합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      int position = 0;

      // Find the index of the soft hyphen using culture-sensitive comparison.
      position = ci.LastIndexOf(s1, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', position,
                           position + 1, CompareOptions.IgnoreCase));

      position = ci.LastIndexOf(s2, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', position,
                           position + 1, CompareOptions.IgnoreCase));

      // Find the index of the soft hyphen using ordinal comparison.
      position = ci.LastIndexOf(s1, 'm');
      Console.WriteLine("'m' at position {0}", position, CompareOptions.Ordinal);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', position,
                           position + 1, CompareOptions.Ordinal));

      position = ci.LastIndexOf(s2, 'm');
      Console.WriteLine("'m' at position {0}", position, CompareOptions.Ordinal);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', position,
                           position + 1, CompareOptions.Ordinal));
   }
}
// The example displays the following output:
//       'm' at position 4
//       4
//       'm' at position 3
//       3
//       'm' at position 4
//       3
//       'm' at position 3
//       -1

추가 정보

적용 대상

LastIndexOf(String, String, Int32, Int32)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex, int count);
public:
 int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex, int count);
public virtual int LastIndexOf (string source, string value, int startIndex, int count);
public int LastIndexOf (string source, string value, int startIndex, int count);
abstract member LastIndexOf : string * string * int * int -> int
override this.LastIndexOf : string * string * int * int -> int
member this.LastIndexOf : string * string * int * int -> int
Public Overridable Function LastIndexOf (source As String, value As String, startIndex As Integer, count As Integer) As Integer
Public Function LastIndexOf (source As String, value As String, startIndex As Integer, count As Integer) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
String

source에서 찾을 문자열입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

count
Int32

검색할 섹션에 있는 요소 수입니다.

반환

Int32

valuesource로 지정된 수의 요소를 포함하고 count에서 끝나는 영역에서 startIndex를 찾은 경우 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

또는

value이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

또는

count가 0보다 작은 경우

또는

startIndexcountsource의 올바른 섹션을 지정하지 않습니다.

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 8;
   
   // iL is the length of the substring.
   int iL = 18;
   
   // myT1 and myT2 are the strings used for padding.
   String^ myT1 = gcnew String( '-',iS );
   String^ myT2;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 8;
      // iL is the length of the substring.
      int iL = 18;
      // myT1 and myT2 are the strings used for padding.
      String myT1 = new String( '-', iS );
      String myT2;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 8
      ' iL is the length of the substring.
      Dim iL As Integer = 18
      ' myT1 and myT2 are the strings used for padding.
      Dim myT1 As New [String]("-"c, [iS])
      Dim myT2 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------- ae the same as Æ -----
'           AE :                         b
'           ae :          b
'            Æ :                         b
'            æ :          b
'Ordinal       : -------- ae the same as Æ -----
'           AE :
'           ae :          b
'            Æ :                         b
'            æ :
'IgnoreCase    : -------- ae the same as Æ -----
'           AE :          f              l
'           ae :          f              l
'            Æ :          f              l
'            æ :          f              l
'
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------- u" the same as Ü -----
'           U" :                         b
'           u" :          b
'            Ü :                         b
'            ü :          b
'Ordinal       : -------- u" the same as Ü -----
'           U" :
'           u" :          b
'            Ü :                         b
'            ü :
'IgnoreCase    : -------- u" the same as Ü -----
'           U" :          f              l
'           u" :          f              l
'            Ü :          f              l
'            ü :          f              l

설명

원본 문자열은 +1부터 startIndex startIndex - count 시작하여 끝나는 뒤로 검색됩니다.

이 오버로드는 문화권에 민감한 검색을 수행합니다. 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 유니코드 값이 비교되는 서수(문화권 구분 안 함) 검색을 수행하려면 형식 CompareOptions 매개 변수가 있는 오버로드 중 하나를 호출하고 값을 사용해야 Ordinal 합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권 구분 검색에서는 value에 무시할 수 있는 문자가 포함된 경우 결과는 해당 문자가 제거된 대상을 검색하는 것과 같습니다. 하나 이상의 무시 가능한 문자로만 구성된 경우 value 메서드는 LastIndexOf(String, String, Int32, Int32) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다.

다음 예제 LastIndexOf(String, String, Int32, Int32) 에서는 메서드를 사용하여 소프트 하이픈(U+00AD)의 위치를 찾은 다음 두 문자열의 마지막 "m" 앞에 오는 세 문자에서 "m"을 찾습니다. 문자열 중 하나에만 필수 부분 문자열이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 메서드는 문화권 구분 비교를 수행할 때 문자열에서 "m"의 인덱스를 반환합니다. "m"이 앞에 붙은 사용자 지정 하이픈이 포함된 첫 번째 문자열의 경우, 메서드가 사용자 지정 하이픈의 인덱스를 반환하지 못하고 대신 "m"의 인덱스를 반환합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string searchString = "\u00ADm";
      string s1 = "ani\u00ADmal" ;
      string s2 = "animal";
      int position;

      position = ci.LastIndexOf(s1, 'm');
      if (position >= 0) {
         Console.WriteLine(ci.LastIndexOf(s1, searchString, position, 3, CompareOptions.None));
         Console.WriteLine(ci.LastIndexOf(s1, searchString, position, 3, CompareOptions.Ordinal));
      }

      position = ci.LastIndexOf(s2, 'm');
      if (position >= 0) {
         Console.WriteLine(ci.LastIndexOf(s2, searchString, position, 3, CompareOptions.None));
         Console.WriteLine(ci.LastIndexOf(s2, searchString, position, 3, CompareOptions.Ordinal));
      }
   }
}
// The example displays the following output:
//       4
//       3
//       3
//       -1

추가 정보

적용 대상

LastIndexOf(String, String, Int32, CompareOptions)

소스 문자열 중 문자열의 시작 부분부터 지정된 인덱스까지의 영역에서 지정된 CompareOptions 값을 사용하여 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex, System::Globalization::CompareOptions options);
public:
 int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex, System::Globalization::CompareOptions options);
public virtual int LastIndexOf (string source, string value, int startIndex, System.Globalization.CompareOptions options);
public int LastIndexOf (string source, string value, int startIndex, System.Globalization.CompareOptions options);
abstract member LastIndexOf : string * string * int * System.Globalization.CompareOptions -> int
override this.LastIndexOf : string * string * int * System.Globalization.CompareOptions -> int
member this.LastIndexOf : string * string * int * System.Globalization.CompareOptions -> int
Public Overridable Function LastIndexOf (source As String, value As String, startIndex As Integer, options As CompareOptions) As Integer
Public Function LastIndexOf (source As String, value As String, startIndex As Integer, options As CompareOptions) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
String

source에서 찾을 문자열입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

options
CompareOptions

sourcevalue을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

Int32

valuesource의 맨 앞부터 source까지의 영역에서 지정된 비교 옵션을 사용하여 startIndex를 찾은 경우 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

또는

value이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

options에 잘못된 CompareOptions 값이 포함된 경우

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다. IndexOf LastIndexOf 동일한 startIndex 매개 변수를 사용하더라도 문자열의 여러 부분에서 검색하고 있습니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 20;
   
   // myT1 is the string used for padding.
   String^ myT1;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 20;
      // myT1 is the string used for padding.
      String myT1;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 20
      ' myT1 is the string used for padding.
      Dim myT1 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS]), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS]), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS]), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS]))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS]))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS]))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.Ordinal))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.Ordinal))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS]), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS]))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS]))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS]))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))
      
      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'IndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                              f
'            Æ :                         f
'            æ :                              f
'Ordinal       : -------------------- as Æ or æ?
'           AE :
'           ae :
'            Æ :                         f
'            æ :                              f
'IgnoreCase    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                         f
'            Æ :                         f
'            æ :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :    l
'            æ :          l
'Ordinal       : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :
'            æ :
'IgnoreCase    : Is AE or ae the same ----------
'           AE :          l
'           ae :          l
'            Æ :          l
'            æ :          l
'
'IndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                              f
'            Ü :                         f
'            ü :                              f
'Ordinal       : -------------------- as Ü or ü?
'           U" :
'           u" :
'            Ü :                         f
'            ü :                              f
'IgnoreCase    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                         f
'            Ü :                         f
'            ü :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :    l
'            ü :          l
'Ordinal       : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :
'            ü :
'IgnoreCase    : Is U" or u" the same ----------
'           U" :          l
'           u" :          l
'            Ü :          l
'            ü :          l

설명

원본 문자열은 문자열의 시작 부분에서 startIndex 시작하여 끝나는 뒤로 검색됩니다.

CompareOptions.StringSort 메서드에 대한 값이 잘못되었습니다.

options 값이 Ordinal 포함되지 않으면 이 오버로드는 문화권에 민감한 검색을 수행합니다. 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 값이 Ordinal 포함된 경우 options 이 오버로드는 유니코드 값이 비교되는 서수(문화권을 구분하지 않는) 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권 구분 검색(즉, optionsOrdinal 또는 OrdinalIgnoreCase가 아닌 경우)에서는 value에 무시할 수 있는 문자가 포함된 경우 결과는 해당 문자가 제거된 대상을 검색하는 것과 같습니다. 하나 이상의 무시 가능한 문자로만 구성된 경우 value 메서드는 LastIndexOf(String, String, Int32, CompareOptions) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다.

다음 예제 LastIndexOf(String, String, Int32, CompareOptions) 에서는 메서드를 사용하여 두 문자열의 마지막 "m"부터 시작하여 소프트 하이픈(U+00AD) 뒤에 "m"의 위치를 찾습니다. 문자열 중 하나에만 필수 부분 문자열이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 메서드는 문화권 구분 비교를 수행할 때 문자열에서 "m"의 인덱스를 반환합니다. "m"이 앞에 붙은 사용자 지정 하이픈이 포함된 첫 번째 문자열의 경우, 메서드가 사용자 지정 하이픈의 인덱스를 반환하지 못하고 대신 "m"의 인덱스를 반환합니다. 메서드는 서수 비교를 수행하는 경우에만 첫 번째 문자열에서 사용자 지정 하이픈의 인덱스를 반환합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string searchString = "\u00ADm";
      string s1 = "ani\u00ADmal" ;
      string s2 = "animal";
      int position;

      position = ci.LastIndexOf(s1, 'm');
      if (position >= 0) {
         Console.WriteLine(ci.LastIndexOf(s1, searchString, position, CompareOptions.None));
         Console.WriteLine(ci.LastIndexOf(s1, searchString, position, CompareOptions.Ordinal));
      }

      position = ci.LastIndexOf(s2, 'm');
      if (position >= 0) {
         Console.WriteLine(ci.LastIndexOf(s2, searchString, position, CompareOptions.None));
         Console.WriteLine(ci.LastIndexOf(s2, searchString, position, CompareOptions.Ordinal));
      }
   }
}
// The example displays the following output:
//       4
//       3
//       3
//       -1

추가 정보

적용 대상

LastIndexOf(String, Char, Int32, Int32)

소스 문자열 중 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 영역에서 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, char value, int startIndex, int count);
public:
 int LastIndexOf(System::String ^ source, char value, int startIndex, int count);
public virtual int LastIndexOf (string source, char value, int startIndex, int count);
public int LastIndexOf (string source, char value, int startIndex, int count);
abstract member LastIndexOf : string * char * int * int -> int
override this.LastIndexOf : string * char * int * int -> int
member this.LastIndexOf : string * char * int * int -> int
Public Overridable Function LastIndexOf (source As String, value As Char, startIndex As Integer, count As Integer) As Integer
Public Function LastIndexOf (source As String, value As Char, startIndex As Integer, count As Integer) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
Char

source에서 찾을 문자입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

count
Int32

검색할 섹션에 있는 요소 수입니다.

반환

Int32

valuesource로 지정된 수의 요소를 포함하고 count에서 끝나는 영역에서 startIndex를 찾은 경우 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

또는

count가 0보다 작은 경우

또는

startIndexcountsource의 올바른 섹션을 지정하지 않습니다.

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 8;
   
   // iL is the length of the substring.
   int iL = 18;
   
   // myT1 and myT2 are the strings used for padding.
   String^ myT1 = gcnew String( '-',iS );
   String^ myT2;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   myT2 = gcnew String( '-',myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL ) );
   Console::WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 8;
      // iL is the length of the substring.
      int iL = 18;
      // myT1 and myT2 are the strings used for padding.
      String myT1 = new String( '-', iS );
      String myT2;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      myT2 = new String( '-', myStr.Length - iS - iL );
      Console.WriteLine();
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL ) );
      Console.WriteLine( "Ordinal       : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring( iS, iL ), myT2 );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, iL, CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', iS + iL - 1, iL, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

Original      : Is AE or ae the same as Æ or æ?
No options    : -------- ae the same as Æ -----
           AE :                         b
           ae :          b
            Æ :                         b
            æ :          b
Ordinal       : -------- ae the same as Æ -----
           AE :
           ae :          b
            Æ :                         b
            æ :
IgnoreCase    : -------- ae the same as Æ -----
           AE :          f              l
           ae :          f              l
            Æ :          f              l
            æ :          f              l

Original      : Is U" or u" the same as Ü or ü?
No options    : -------- u" the same as Ü -----
           U" :                         b
           u" :          b
            Ü :                         b
            ü :          b
Ordinal       : -------- u" the same as Ü -----
           U" :
           u" :          b
            Ü :                         b
            ü :
IgnoreCase    : -------- u" the same as Ü -----
           U" :          f              l
           u" :          f              l
            Ü :          f              l
            ü :          f              l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 8
      ' iL is the length of the substring.
      Dim iL As Integer = 18
      ' myT1 and myT2 are the strings used for padding.
      Dim myT1 As New [String]("-"c, [iS])
      Dim myT2 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      myT2 = New [String]("-"c, myStr.Length - [iS] - iL)
      Console.WriteLine()
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL))
      Console.WriteLine("Ordinal       : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}{2}", myT1, myStr.Substring([iS], iL), myT2)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], iL, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, [iS] + iL - 1, iL, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------- ae the same as Æ -----
'           AE :                         b
'           ae :          b
'            Æ :                         b
'            æ :          b
'Ordinal       : -------- ae the same as Æ -----
'           AE :
'           ae :          b
'            Æ :                         b
'            æ :
'IgnoreCase    : -------- ae the same as Æ -----
'           AE :          f              l
'           ae :          f              l
'            Æ :          f              l
'            æ :          f              l
'
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------- u" the same as Ü -----
'           U" :                         b
'           u" :          b
'            Ü :                         b
'            ü :          b
'Ordinal       : -------- u" the same as Ü -----
'           U" :
'           u" :          b
'            Ü :                         b
'            ü :
'IgnoreCase    : -------- u" the same as Ü -----
'           U" :          f              l
'           u" :          f              l
'            Ü :          f              l
'            ü :          f              l

설명

원본 문자열은 +1부터 startIndex startIndex - count 시작하여 끝나는 뒤로 검색됩니다.

이 오버로드는 문화권에 민감한 검색을 수행합니다. 문자가 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값인 경우 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스의 구성 요소 발생과 동일한 것으로 간주될 수 있습니다. 서수(문화권을 구분하지 않는) 검색을 수행하려면 유니코드 값이 동일한 경우에만 문자가 다른 문자와 동등한 것으로 간주되는 경우 형식 CompareOptions 매개 변수가 있는 오버로드 중 하나를 호출하고 값을 사용해야 Ordinal 합니다. 해당 검색의 String.LastIndexOf 오버로드는 서수 검색을 수행하는 반면 문자열을 검색하는 오버로드는 문화권에 민감한 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권에 민감한 검색에서 무시할 수 있는 문자인 경우 value 결과는 해당 문자를 제거한 상태에서 검색하는 것과 같습니다. 이 경우 메서드는 LastIndexOf(String, Char, Int32, Int32) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다. 다음 예제 LastIndexOf(String, Char, Int32, Int32) 에서는 메서드를 사용하여 두 문자열의 마지막 "m" 앞에 오는 소프트 하이픈(U+00AD)을 찾습니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 메서드는 값인 "m" startIndex의 인덱스 위치를 반환합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      int position = 0;

      // Find the index of the soft hyphen.
      position = ci.IndexOf(s1, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', position, position + 1));

      position = ci.IndexOf(s2, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', position, position + 1));
   }
}
// The example displays the following output:
//       'm' at position 4
//       4
//       'm' at position 3
//       3

추가 정보

적용 대상

LastIndexOf(String, Char, Int32, CompareOptions)

소스 문자열 중 문자열의 시작 부분부터 지정된 인덱스까지의 영역에서 지정된 CompareOptions 값을 사용하여 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, char value, int startIndex, System::Globalization::CompareOptions options);
public:
 int LastIndexOf(System::String ^ source, char value, int startIndex, System::Globalization::CompareOptions options);
public virtual int LastIndexOf (string source, char value, int startIndex, System.Globalization.CompareOptions options);
public int LastIndexOf (string source, char value, int startIndex, System.Globalization.CompareOptions options);
abstract member LastIndexOf : string * char * int * System.Globalization.CompareOptions -> int
override this.LastIndexOf : string * char * int * System.Globalization.CompareOptions -> int
member this.LastIndexOf : string * char * int * System.Globalization.CompareOptions -> int
Public Overridable Function LastIndexOf (source As String, value As Char, startIndex As Integer, options As CompareOptions) As Integer
Public Function LastIndexOf (source As String, value As Char, startIndex As Integer, options As CompareOptions) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
Char

source에서 찾을 문자입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

options
CompareOptions

sourcevalue을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

Int32

valuesource의 맨 앞부터 source까지의 영역에서 지정된 비교 옵션을 사용하여 startIndex를 찾은 경우 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

options에 잘못된 CompareOptions 값이 포함된 경우

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다. IndexOf LastIndexOf 동일한 startIndex 매개 변수를 사용하더라도 문자열의 여러 부분에서 검색하고 있습니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 20;
   
   // myT1 is the string used for padding.
   String^ myT1;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 20;
      // myT1 is the string used for padding.
      String myT1;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 20
      ' myT1 is the string used for padding.
      Dim myT1 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS]), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS]), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS]), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS]))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS]))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS]))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.Ordinal))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.Ordinal))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS]), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS]))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS]))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS]))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))
      
      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'IndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                              f
'            Æ :                         f
'            æ :                              f
'Ordinal       : -------------------- as Æ or æ?
'           AE :
'           ae :
'            Æ :                         f
'            æ :                              f
'IgnoreCase    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                         f
'            Æ :                         f
'            æ :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :    l
'            æ :          l
'Ordinal       : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :
'            æ :
'IgnoreCase    : Is AE or ae the same ----------
'           AE :          l
'           ae :          l
'            Æ :          l
'            æ :          l
'
'IndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                              f
'            Ü :                         f
'            ü :                              f
'Ordinal       : -------------------- as Ü or ü?
'           U" :
'           u" :
'            Ü :                         f
'            ü :                              f
'IgnoreCase    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                         f
'            Ü :                         f
'            ü :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :    l
'            ü :          l
'Ordinal       : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :
'            ü :
'IgnoreCase    : Is U" or u" the same ----------
'           U" :          l
'           u" :          l
'            Ü :          l
'            ü :          l

설명

원본 문자열은 문자열의 시작 부분에서 startIndex 시작하여 끝나는 뒤로 검색됩니다.

CompareOptions.StringSort 메서드에 대한 값이 잘못되었습니다.

options 값이 Ordinal 포함되지 않으면 이 오버로드는 문화권에 민감한 검색을 수행합니다. 문자가 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값인 경우 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스의 구성 요소 발생과 동일한 것으로 간주될 수 있습니다. 값이 Ordinal 포함된 경우 options 이 오버로드는 서수(문화권을 구분하지 않는) 검색을 수행합니다. 문자는 유니코드 값이 동일한 경우에만 다른 문자와 동일한 것으로 간주됩니다. 해당 검색의 String.LastIndexOf 오버로드는 서수 검색을 수행하는 반면 문자열을 검색하는 오버로드는 문화권에 민감한 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권에 민감한 검색에서 무시할 수 있는 문자인 경우 value 결과는 해당 문자를 제거한 상태에서 검색하는 것과 같습니다. 이 경우 메서드는 LastIndexOf(String, Char, Int32, CompareOptions) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다. 다음 예제 LastIndexOf(String, Char, Int32, CompareOptions) 에서는 메서드를 사용하여 두 문자열의 마지막 "m" 앞에 오는 소프트 하이픈(U+00AD)을 찾습니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 문화권 구분 검색은 "m"의 인덱스 위치를 반환합니다. 그러나 서수 검색은 한 문자열에서 소프트 하이픈을 찾은 후 두 번째 문자열에 없는 것을 보고합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      int position = 0;

      // Find the index of the soft hyphen using culture-sensitive comparison.
      position = ci.LastIndexOf(s1, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', position, CompareOptions.IgnoreCase));

      position = ci.LastIndexOf(s2, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', position, CompareOptions.IgnoreCase));

      // Find the index of the soft hyphen using ordinal comparison.
      position = ci.LastIndexOf(s1, 'm');
      Console.WriteLine("'m' at position {0}", position, CompareOptions.Ordinal);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', position, CompareOptions.Ordinal));

      position = ci.LastIndexOf(s2, 'm');
      Console.WriteLine("'m' at position {0}", position, CompareOptions.Ordinal);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', position, CompareOptions.Ordinal));
   }
}
// The example displays the following output:
//       'm' at position 4
//       4
//       'm' at position 3
//       3
//       'm' at position 4
//       3
//       'm' at position 3
//       -1

추가 정보

적용 대상

LastIndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

소스 문자열에서 마지막에 나타나는 부분 문자열을 검색합니다.

public:
 int LastIndexOf(ReadOnlySpan<char> source, ReadOnlySpan<char> value, System::Globalization::CompareOptions options, [Runtime::InteropServices::Out] int % matchLength);
public int LastIndexOf (ReadOnlySpan<char> source, ReadOnlySpan<char> value, System.Globalization.CompareOptions options, out int matchLength);
member this.LastIndexOf : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions * int -> int
Public Function LastIndexOf (source As ReadOnlySpan(Of Char), value As ReadOnlySpan(Of Char), options As CompareOptions, ByRef matchLength As Integer) As Integer

매개 변수

source
ReadOnlySpan<Char>

검색할 읽기 전용 문자 범위입니다.

value
ReadOnlySpan<Char>

source에서 찾을 부분 문자열을 포함하는 문자의 읽기 전용 범위입니다.

options
CompareOptions

검색하는 동안 사용할 CompareOptions입니다.

matchLength
Int32

이 메서드가 반환되면 원하는 값과 일치한 source의 문자 수를 포함합니다. 언어 비교가 수행되는 경우 value의 길이와 다를 수 있습니다. valuesource 내에 없는 경우 0으로 설정합니다.

반환

Int32

value 하위 문자열이 마지막으로 나타나는 source에 대한 인덱스(0부터 시작)이거나, source에서 value를 찾을 수 없는 경우 음수입니다.

예외

options에 지원되지 않는 플래그 조합이 포함되어 있습니다.

설명

이 메서드는 인수를 사용하지 matchLength 않는 다른 LastIndexOf 오버로드보다 오버헤드가 더 큽니다. 일치 길이 정보가 필요한 경우에만 이 오버로드를 호출합니다.

적용 대상

LastIndexOf(String, Char)

전체 소스 문자열에서 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, char value);
public:
 int LastIndexOf(System::String ^ source, char value);
public virtual int LastIndexOf (string source, char value);
public int LastIndexOf (string source, char value);
abstract member LastIndexOf : string * char -> int
override this.LastIndexOf : string * char -> int
member this.LastIndexOf : string * char -> int
Public Overridable Function LastIndexOf (source As String, value As Char) As Integer
Public Function LastIndexOf (source As String, value As Char) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
Char

source에서 찾을 문자입니다.

반환

Int32

value에서 source를 찾은 경우 맨 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다.

예외

source이(가) null인 경우

예제

다음 예제에서는 문자열 내의 첫 번째 및 마지막 문자 또는 부분 문자열의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE" ), myComp->LastIndexOf( myStr, "AE" ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae" ), myComp->LastIndexOf( myStr, "ae" ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ' ), myComp->LastIndexOf( myStr, L'Æ' ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ' ), myComp->LastIndexOf( myStr, L'æ' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308" ), myComp->LastIndexOf( myStr, "U\u0308" ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308" ), myComp->LastIndexOf( myStr, "u\u0308" ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü' ), myComp->LastIndexOf( myStr, L'Ü' ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü' ), myComp->LastIndexOf( myStr, L'ü' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE" ), myComp.LastIndexOf( myStr, "AE" ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae" ), myComp.LastIndexOf( myStr, "ae" ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ' ), myComp.LastIndexOf( myStr, 'Æ' ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ' ), myComp.LastIndexOf( myStr, 'æ' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308" ), myComp.LastIndexOf( myStr, "U\u0308" ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308" ), myComp.LastIndexOf( myStr, "u\u0308" ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü' ), myComp.LastIndexOf( myStr, 'Ü' ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü' ), myComp.LastIndexOf( myStr, 'ü' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE"), myComp.LastIndexOf(myStr, "AE"))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae"), myComp.LastIndexOf(myStr, "ae"))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c), myComp.LastIndexOf(myStr, "Æ"c))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c), myComp.LastIndexOf(myStr, "æ"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308)))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308)))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c), myComp.LastIndexOf(myStr, "Ü"c))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c), myComp.LastIndexOf(myStr, "ü"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 
         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'No options    : Is AE or ae the same as Æ or æ?
'           AE :    f                    l
'           ae :          f                   l
'            Æ :    f                    l
'            æ :          f                   l
'Ordinal       : Is AE or ae the same as Æ or æ?
'           AE :    b
'           ae :          b
'            Æ :                         b
'            æ :                              b
'IgnoreCase    : Is AE or ae the same as Æ or æ?
'           AE :    f                         l
'           ae :    f                         l
'            Æ :    f                         l
'            æ :    f                         l
'
'No options    : Is U" or u" the same as Ü or ü?
'           U" :    f                    l
'           u" :          f                   l
'            Ü :    f                    l
'            ü :          f                   l
'Ordinal       : Is U" or u" the same as Ü or ü?
'           U" :    b
'           u" :          b
'            Ü :                         b
'            ü :                              b
'IgnoreCase    : Is U" or u" the same as Ü or ü?
'           U" :    f                         l
'           u" :    f                         l
'            Ü :    f                         l
'            ü :    f                         l

설명

원본 문자열은 문자열의 끝에서 시작하여 문자열의 시작 부분에서 끝나는 뒤로 검색됩니다.

이 오버로드는 문화권에 민감한 검색을 수행합니다. 문자가 합자 "Æ"(U+00C6)와 같이 미리 구성된 문자를 나타내는 유니코드 값인 경우 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 해당 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 유니코드 값이 동일한 경우에만 문자가 다른 문자와 동일한 것으로 간주되는 서수(문화권을 구분하지 않는) 검색을 수행하려면 형식 CompareOptions 매개 변수가 있는 오버로드 중 하나를 호출하고 값을 사용해야 Ordinal 합니다. 문자를 검색하는 오버로드는 서수 검색을 수행하는 반면 문자열을 검색하는 오버로드는 String.LastIndexOf 문화권에 민감한 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 의 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권을 구분하는 검색에서 무시할 수 있는 문자인 경우 value 결과는 해당 문자를 제거한 검색과 동일합니다. 이 경우 메서드는 LastIndexOf(String, Char) 항상 마지막 인덱스 위치를 source 반환하여 일치 항목이 끝에 source있음을 나타냅니다. 다음 예제 LastIndexOf(String, Char) 에서는 이 메서드를 사용하여 두 문자열에서 소프트 하이픈(U+00AD)을 찾습니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 메서드는 문자열의 마지막 인덱스 위치를 반환하여 문자열의 끝에 일치하는 항목이 있음을 나타냅니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      // Find the index of the last soft hyphen.
      Console.WriteLine(ci.LastIndexOf(s1, '\u00AD'));
      Console.WriteLine(ci.LastIndexOf(s2, '\u00AD'));
   }
}
// The example displays the following output:
//       6
//       5

추가 정보

적용 대상

LastIndexOf(String, String, CompareOptions)

전체 소스 문자열에서 지정된 CompareOptions 값을 사용하여 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, System::String ^ value, System::Globalization::CompareOptions options);
public:
 int LastIndexOf(System::String ^ source, System::String ^ value, System::Globalization::CompareOptions options);
public virtual int LastIndexOf (string source, string value, System.Globalization.CompareOptions options);
public int LastIndexOf (string source, string value, System.Globalization.CompareOptions options);
abstract member LastIndexOf : string * string * System.Globalization.CompareOptions -> int
override this.LastIndexOf : string * string * System.Globalization.CompareOptions -> int
member this.LastIndexOf : string * string * System.Globalization.CompareOptions -> int
Public Overridable Function LastIndexOf (source As String, value As String, options As CompareOptions) As Integer
Public Function LastIndexOf (source As String, value As String, options As CompareOptions) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
String

source에서 찾을 문자열입니다.

options
CompareOptions

sourcevalue을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

Int32

value에서 지정된 비교 옵션을 사용하여 source를 찾은 경우 맨 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다.

예외

source이(가) null인 경우

또는

value이(가) null인 경우

options에 잘못된 CompareOptions 값이 포함된 경우

예제

다음 예제에서는 문자열 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE" ), myComp->LastIndexOf( myStr, "AE" ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae" ), myComp->LastIndexOf( myStr, "ae" ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ' ), myComp->LastIndexOf( myStr, L'Æ' ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ' ), myComp->LastIndexOf( myStr, L'æ' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308" ), myComp->LastIndexOf( myStr, "U\u0308" ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308" ), myComp->LastIndexOf( myStr, "u\u0308" ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü' ), myComp->LastIndexOf( myStr, L'Ü' ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü' ), myComp->LastIndexOf( myStr, L'ü' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE" ), myComp.LastIndexOf( myStr, "AE" ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae" ), myComp.LastIndexOf( myStr, "ae" ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ' ), myComp.LastIndexOf( myStr, 'Æ' ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ' ), myComp.LastIndexOf( myStr, 'æ' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308" ), myComp.LastIndexOf( myStr, "U\u0308" ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308" ), myComp.LastIndexOf( myStr, "u\u0308" ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü' ), myComp.LastIndexOf( myStr, 'Ü' ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü' ), myComp.LastIndexOf( myStr, 'ü' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE"), myComp.LastIndexOf(myStr, "AE"))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae"), myComp.LastIndexOf(myStr, "ae"))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c), myComp.LastIndexOf(myStr, "Æ"c))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c), myComp.LastIndexOf(myStr, "æ"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308)))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308)))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c), myComp.LastIndexOf(myStr, "Ü"c))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c), myComp.LastIndexOf(myStr, "ü"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 
         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'No options    : Is AE or ae the same as Æ or æ?
'           AE :    f                    l
'           ae :          f                   l
'            Æ :    f                    l
'            æ :          f                   l
'Ordinal       : Is AE or ae the same as Æ or æ?
'           AE :    b
'           ae :          b
'            Æ :                         b
'            æ :                              b
'IgnoreCase    : Is AE or ae the same as Æ or æ?
'           AE :    f                         l
'           ae :    f                         l
'            Æ :    f                         l
'            æ :    f                         l
'
'No options    : Is U" or u" the same as Ü or ü?
'           U" :    f                    l
'           u" :          f                   l
'            Ü :    f                    l
'            ü :          f                   l
'Ordinal       : Is U" or u" the same as Ü or ü?
'           U" :    b
'           u" :          b
'            Ü :                         b
'            ü :                              b
'IgnoreCase    : Is U" or u" the same as Ü or ü?
'           U" :    f                         l
'           u" :    f                         l
'            Ü :    f                         l
'            ü :    f                         l

설명

원본 문자열은 문자열의 끝에서 시작하여 문자열의 시작 부분에서 끝나는 뒤로 검색됩니다.

CompareOptions.StringSort 메서드에 대한 값이 잘못되었습니다.

options 값이 Ordinal 포함되지 않으면 이 오버로드는 문화권에 민감한 검색을 수행합니다. 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 값이 Ordinal 포함된 경우 options 이 오버로드는 유니코드 값이 비교되는 서수(문화권을 구분하지 않는) 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권 구분 검색(즉, optionsOrdinal 또는 OrdinalIgnoreCase가 아닌 경우)에서는 value에 무시할 수 있는 문자가 포함된 경우 결과는 해당 문자가 제거된 대상을 검색하는 것과 같습니다. 하나 이상의 무시 가능한 문자로만 구성된 경우 value 메서드는 LastIndexOf(String, String, CompareOptions) 항상 반환합니다 source.Length - 1- 의 마지막 인덱스 위치를 source나타냅니다. 다음 예제 LastIndexOf(String, String, CompareOptions) 에서 메서드는 두 문자열에서 세 개의 부분 문자열(소프트 하이픈(U+00AD), 소프트 하이픈, "n", 소프트 하이픈, "m"을 찾는 데 사용됩니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 소프트 하이픈은 무시할 수 있는 문자이므로 문화권 구분 검색은 소프트 하이픈이 검색 문자열에 포함되지 않은 경우 반환하는 것과 동일한 값을 반환합니다. 그러나 서수 검색은 한 문자열에서 소프트 하이픈을 찾은 후 두 번째 문자열에 없는 것을 보고합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      Console.WriteLine("Culture-sensitive comparison:");
      // Use culture-sensitive comparison to find the last soft hyphen.
      Console.WriteLine(ci.LastIndexOf(s1, "\u00AD", CompareOptions.None));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00AD", CompareOptions.None));

      // Use culture-sensitive comparison to find the last soft hyphen followed by "n".
      Console.WriteLine(ci.LastIndexOf(s1, "\u00ADn", CompareOptions.None));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00ADn", CompareOptions.None));

      // Use culture-sensitive comparison to find the last soft hyphen followed by "m".
      Console.WriteLine(ci.LastIndexOf(s1, "\u00ADm", CompareOptions.None));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00ADm", CompareOptions.None));

      Console.WriteLine("Ordinal comparison:");
      // Use ordinal comparison to find the last soft hyphen.
      Console.WriteLine(ci.LastIndexOf(s1, "\u00AD", CompareOptions.Ordinal));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00AD", CompareOptions.Ordinal));

      // Use ordinal comparison to find the last soft hyphen followed by "n".
      Console.WriteLine(ci.LastIndexOf(s1, "\u00ADn", CompareOptions.Ordinal));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00ADn", CompareOptions.Ordinal));

      // Use ordinal comparison to find the last soft hyphen followed by "m".
      Console.WriteLine(ci.LastIndexOf(s1, "\u00ADm", CompareOptions.Ordinal));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00ADm", CompareOptions.Ordinal));
   }
}
// The example displays the following output:
//       6
//       5
//       1
//       1
//       4
//       3
//       Ordinal comparison:
//       3
//       -1
//       -1
//       -1
//       3
//       -1

추가 정보

적용 대상

LastIndexOf(String, Char, Int32)

소스 문자열 중 처음부터 지정된 인덱스까지의 영역에서 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 int LastIndexOf(System::String ^ source, char value, int startIndex);
public:
 virtual int LastIndexOf(System::String ^ source, char value, int startIndex);
public int LastIndexOf (string source, char value, int startIndex);
public virtual int LastIndexOf (string source, char value, int startIndex);
member this.LastIndexOf : string * char * int -> int
abstract member LastIndexOf : string * char * int -> int
override this.LastIndexOf : string * char * int -> int
Public Function LastIndexOf (source As String, value As Char, startIndex As Integer) As Integer
Public Overridable Function LastIndexOf (source As String, value As Char, startIndex As Integer) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
Char

source에서 찾을 문자입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

반환

Int32

valuesource의 맨 앞부터 source까지의 영역에서 startIndex를 찾은 경우 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 발생의 인덱스를 결정합니다. IndexOf LastIndexOf 동일한 startIndex 매개 변수를 사용하더라도 문자열의 다른 부분에서 검색하고 있습니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 20;
   
   // myT1 is the string used for padding.
   String^ myT1;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 20;
      // myT1 is the string used for padding.
      String myT1;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 20
      ' myT1 is the string used for padding.
      Dim myT1 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS]), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS]), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS]), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS]))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS]))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS]))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.Ordinal))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.Ordinal))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS]), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS]))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS]))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS]))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))
      
      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'IndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                              f
'            Æ :                         f
'            æ :                              f
'Ordinal       : -------------------- as Æ or æ?
'           AE :
'           ae :
'            Æ :                         f
'            æ :                              f
'IgnoreCase    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                         f
'            Æ :                         f
'            æ :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :    l
'            æ :          l
'Ordinal       : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :
'            æ :
'IgnoreCase    : Is AE or ae the same ----------
'           AE :          l
'           ae :          l
'            Æ :          l
'            æ :          l
'
'IndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                              f
'            Ü :                         f
'            ü :                              f
'Ordinal       : -------------------- as Ü or ü?
'           U" :
'           u" :
'            Ü :                         f
'            ü :                              f
'IgnoreCase    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                         f
'            Ü :                         f
'            ü :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :    l
'            ü :          l
'Ordinal       : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :
'            ü :
'IgnoreCase    : Is U" or u" the same ----------
'           U" :          l
'           u" :          l
'            Ü :          l
'            ü :          l

설명

원본 문자열은 문자열의 시작 부분에서 startIndex 시작하여 끝나는 뒤로 검색됩니다.

이 오버로드는 문화권에 민감한 검색을 수행합니다. 문자가 합자 "Æ"(U+00C6)와 같이 미리 구성된 문자를 나타내는 유니코드 값인 경우 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 해당 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 유니코드 값이 동일한 경우에만 문자가 다른 문자와 동일한 것으로 간주되는 서수(문화권을 구분하지 않는) 검색을 수행하려면 형식 CompareOptions 매개 변수가 있는 오버로드 중 하나를 호출하고 값을 사용해야 Ordinal 합니다. 문자를 검색하는 오버로드는 서수 검색을 수행하는 반면 문자열을 검색하는 오버로드는 String.LastIndexOf 문화권에 민감한 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 의 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권을 구분하는 검색에서 무시할 수 있는 문자인 경우 value 결과는 해당 문자를 제거한 검색과 동일합니다. 이 경우 메서드는 LastIndexOf(String, Char, Int32) 검색이 시작되는 문자 위치인 항상 반환 startIndex합니다. 다음 예제 LastIndexOf(String, Char, Int32) 에서는 메서드를 사용하여 두 문자열에서 마지막 "m" 앞에 오는 소프트 하이픈(U+00AD)을 찾습니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시 가능한 문자이므로 메서드는 값인 "m" startIndex의 인덱스 위치를 반환합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      int position = 0;

      // Find the last index of the soft hyphen.
      position = ci.LastIndexOf(s1, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', position));

      position = ci.LastIndexOf(s2, 'm');
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', position));
   }
}
// The example displays the following output:
//       'm' at position 4
//       4
//       'm' at position 3

추가 정보

적용 대상

LastIndexOf(String, Char, CompareOptions)

전체 소스 문자열에서 지정된 CompareOptions 값을 사용하여 지정된 문자를 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, char value, System::Globalization::CompareOptions options);
public:
 int LastIndexOf(System::String ^ source, char value, System::Globalization::CompareOptions options);
public virtual int LastIndexOf (string source, char value, System.Globalization.CompareOptions options);
public int LastIndexOf (string source, char value, System.Globalization.CompareOptions options);
abstract member LastIndexOf : string * char * System.Globalization.CompareOptions -> int
override this.LastIndexOf : string * char * System.Globalization.CompareOptions -> int
member this.LastIndexOf : string * char * System.Globalization.CompareOptions -> int
Public Overridable Function LastIndexOf (source As String, value As Char, options As CompareOptions) As Integer
Public Function LastIndexOf (source As String, value As Char, options As CompareOptions) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
Char

source에서 찾을 문자입니다.

options
CompareOptions

sourcevalue을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

Int32

value에서 지정된 비교 옵션을 사용하여 source를 찾은 경우 맨 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다.

예외

source이(가) null인 경우

options에 잘못된 CompareOptions 값이 포함된 경우

예제

다음 예제에서는 문자열 내의 첫 번째 및 마지막 문자 또는 부분 문자열의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE" ), myComp->LastIndexOf( myStr, "AE" ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae" ), myComp->LastIndexOf( myStr, "ae" ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ' ), myComp->LastIndexOf( myStr, L'Æ' ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ' ), myComp->LastIndexOf( myStr, L'æ' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308" ), myComp->LastIndexOf( myStr, "U\u0308" ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308" ), myComp->LastIndexOf( myStr, "u\u0308" ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü' ), myComp->LastIndexOf( myStr, L'Ü' ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü' ), myComp->LastIndexOf( myStr, L'ü' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE" ), myComp.LastIndexOf( myStr, "AE" ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae" ), myComp.LastIndexOf( myStr, "ae" ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ' ), myComp.LastIndexOf( myStr, 'Æ' ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ' ), myComp.LastIndexOf( myStr, 'æ' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308" ), myComp.LastIndexOf( myStr, "U\u0308" ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308" ), myComp.LastIndexOf( myStr, "u\u0308" ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü' ), myComp.LastIndexOf( myStr, 'Ü' ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü' ), myComp.LastIndexOf( myStr, 'ü' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE"), myComp.LastIndexOf(myStr, "AE"))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae"), myComp.LastIndexOf(myStr, "ae"))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c), myComp.LastIndexOf(myStr, "Æ"c))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c), myComp.LastIndexOf(myStr, "æ"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308)))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308)))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c), myComp.LastIndexOf(myStr, "Ü"c))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c), myComp.LastIndexOf(myStr, "ü"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 
         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'No options    : Is AE or ae the same as Æ or æ?
'           AE :    f                    l
'           ae :          f                   l
'            Æ :    f                    l
'            æ :          f                   l
'Ordinal       : Is AE or ae the same as Æ or æ?
'           AE :    b
'           ae :          b
'            Æ :                         b
'            æ :                              b
'IgnoreCase    : Is AE or ae the same as Æ or æ?
'           AE :    f                         l
'           ae :    f                         l
'            Æ :    f                         l
'            æ :    f                         l
'
'No options    : Is U" or u" the same as Ü or ü?
'           U" :    f                    l
'           u" :          f                   l
'            Ü :    f                    l
'            ü :          f                   l
'Ordinal       : Is U" or u" the same as Ü or ü?
'           U" :    b
'           u" :          b
'            Ü :                         b
'            ü :                              b
'IgnoreCase    : Is U" or u" the same as Ü or ü?
'           U" :    f                         l
'           u" :    f                         l
'            Ü :    f                         l
'            ü :    f                         l

설명

원본 문자열은 문자열의 끝에서 시작하여 문자열의 시작 부분에서 끝나는 뒤로 검색됩니다.

이 메서드에 CompareOptions.StringSort 대한 값이 잘못되었습니다.

options 값이 Ordinal 포함되지 않으면 이 오버로드는 문화권에 민감한 검색을 수행합니다. 문자가 합자 "Æ"(U+00C6)와 같이 미리 구성된 문자를 나타내는 유니코드 값인 경우 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 해당 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 값이 Ordinal 포함된 경우 options 이 오버로드는 서수(문화권을 구분하지 않는) 검색을 수행합니다. 문자는 유니코드 값이 동일한 경우에만 다른 문자와 동일한 것으로 간주됩니다. 문자를 검색하는 오버로드는 서수 검색을 수행하는 반면 문자열을 검색하는 오버로드는 String.LastIndexOf 문화권에 민감한 검색을 수행합니다.

참고

가능하면 형식 CompareOptions 의 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권을 구분하는 검색에서 무시할 수 있는 문자인 경우 value 결과는 해당 문자를 제거한 검색과 동일합니다. 이 경우 메서드는 LastIndexOf(String, Char, CompareOptions) 항상 마지막 문자 위치를 source 반환하여 일치 항목이 끝에 source있음을 나타냅니다. 다음 예제 LastIndexOf(String, Char, CompareOptions) 에서 메서드는 두 문자열에서 소프트 하이픈(U+00AD)을 검색하는 데 사용됩니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 두 경우 모두 소프트 하이픈은 무시할 수 있는 문자이므로 문화권 구분 검색은 원본 문자열의 마지막 인덱스 위치를 반환합니다. 반면 서수 검색은 한 문자열에서 소프트 하이픈을 성공적으로 찾고 두 번째 문자열에 없는 것을 보고합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      // Find the last index of the soft hyphen using culture-sensitive comparison.
      Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', CompareOptions.IgnoreCase));
      Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', CompareOptions.IgnoreCase));

      // Find the last index of the soft hyphen using ordinal comparison.
      Console.WriteLine(ci.LastIndexOf(s1, '\u00AD', CompareOptions.Ordinal));
      Console.WriteLine(ci.LastIndexOf(s2, '\u00AD', CompareOptions.Ordinal));
   }
}
// The example displays the following output:
//       6
//       5
//       3
//       -1

추가 정보

적용 대상

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

지정된 읽기 전용 문자 범위 내에서 마지막 Rune을 검색합니다.

public int LastIndexOf (ReadOnlySpan<char> source, System.Text.Rune value, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);
member this.LastIndexOf : ReadOnlySpan<char> * System.Text.Rune * System.Globalization.CompareOptions -> int
Public Function LastIndexOf (source As ReadOnlySpan(Of Char), value As Rune, Optional options As CompareOptions = System.Globalization.CompareOptions.None) As Integer

매개 변수

source
ReadOnlySpan<Char>

검색할 읽기 전용 문자 범위입니다.

value
Rune

source에서 찾을 Rune입니다.

options
CompareOptions

검색하는 동안 사용할 CompareOptions 열거형 값의 선택적 조합입니다. 기본값은 None입니다.

반환

Int32

value가 마지막으로 나타나는 source에 대한 인덱스(0부터 시작)이고, source에서 value를 찾을 수 없는 경우 음수 값입니다.

예외

options에 지원되지 않는 플래그 조합이 포함되어 있습니다.

적용 대상

LastIndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

지정된 읽기 전용 문자 범위 내에서 마지막 하위 문자열을 검색합니다.

public int LastIndexOf (ReadOnlySpan<char> source, ReadOnlySpan<char> value, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);
member this.LastIndexOf : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions -> int
Public Function LastIndexOf (source As ReadOnlySpan(Of Char), value As ReadOnlySpan(Of Char), Optional options As CompareOptions = System.Globalization.CompareOptions.None) As Integer

매개 변수

source
ReadOnlySpan<Char>

검색할 읽기 전용 문자 범위입니다.

value
ReadOnlySpan<Char>

source에서 찾을 하위 문자열입니다.

options
CompareOptions

검색하는 동안 사용할 CompareOptions 열거형 값의 선택적 조합입니다. 기본값은 None입니다.

반환

Int32

value 하위 문자열이 마지막으로 나타나는 source에 대한 인덱스(0부터 시작)이거나, source에서 value를 찾을 수 없는 경우 음수 값입니다.

예외

options에 지원되지 않는 플래그 조합이 포함되어 있습니다.

적용 대상

LastIndexOf(String, String)

전체 소스 문자열에서 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 virtual int LastIndexOf(System::String ^ source, System::String ^ value);
public:
 int LastIndexOf(System::String ^ source, System::String ^ value);
public virtual int LastIndexOf (string source, string value);
public int LastIndexOf (string source, string value);
abstract member LastIndexOf : string * string -> int
override this.LastIndexOf : string * string -> int
member this.LastIndexOf : string * string -> int
Public Overridable Function LastIndexOf (source As String, value As String) As Integer
Public Function LastIndexOf (source As String, value As String) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
String

source에서 찾을 문자열입니다.

반환

Int32

value에서 source를 찾은 경우 맨 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다.

예외

source이(가) null인 경우

또는

value이(가) null인 경우

예제

다음 예제에서는 문자열 내의 첫 번째 및 마지막 문자 또는 부분 문자열의 인덱스를 결정합니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE" ), myComp->LastIndexOf( myStr, "AE" ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae" ), myComp->LastIndexOf( myStr, "ae" ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ' ), myComp->LastIndexOf( myStr, L'Æ' ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ' ), myComp->LastIndexOf( myStr, L'æ' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "AE", CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "ae", CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "AE", CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "ae", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Æ', CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'æ', CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   Console::WriteLine( "No options    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308" ), myComp->LastIndexOf( myStr, "U\u0308" ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308" ), myComp->LastIndexOf( myStr, "u\u0308" ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü' ), myComp->LastIndexOf( myStr, L'Ü' ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü' ), myComp->LastIndexOf( myStr, L'ü' ) );
   Console::WriteLine( "Ordinal       : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}", myStr );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "U\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, "u\u0308", CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'Ü', CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ü', CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE" ), myComp.LastIndexOf( myStr, "AE" ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae" ), myComp.LastIndexOf( myStr, "ae" ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ' ), myComp.LastIndexOf( myStr, 'Æ' ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ' ), myComp.LastIndexOf( myStr, 'æ' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "AE", CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "ae", CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "AE", CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "ae", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Æ', CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'æ', CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();
      Console.WriteLine( "No options    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308" ), myComp.LastIndexOf( myStr, "U\u0308" ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308" ), myComp.LastIndexOf( myStr, "u\u0308" ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü' ), myComp.LastIndexOf( myStr, 'Ü' ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü' ), myComp.LastIndexOf( myStr, 'ü' ) );
      Console.WriteLine( "Ordinal       : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.Ordinal ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}", myStr );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "U\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, "u\u0308", CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'Ü', CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', CompareOptions.IgnoreCase ), myComp.LastIndexOf( myStr, 'ü', CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

No options    : Is AE or ae the same as Æ or æ?
           AE :    f                    l
           ae :          f                   l
            Æ :    f                    l
            æ :          f                   l
Ordinal       : Is AE or ae the same as Æ or æ?
           AE :    b
           ae :          b
            Æ :                         b
            æ :                              b
IgnoreCase    : Is AE or ae the same as Æ or æ?
           AE :    f                         l
           ae :    f                         l
            Æ :    f                         l
            æ :    f                         l

No options    : Is U" or u" the same as Ü or ü?
           U" :    f                    l
           u" :          f                   l
            Ü :    f                    l
            ü :          f                   l
Ordinal       : Is U" or u" the same as Ü or ü?
           U" :    b
           u" :          b
            Ü :                         b
            ü :                              b
IgnoreCase    : Is U" or u" the same as Ü or ü?
           U" :    f                         l
           u" :    f                         l
            Ü :    f                         l
            ü :    f                         l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE"), myComp.LastIndexOf(myStr, "AE"))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae"), myComp.LastIndexOf(myStr, "ae"))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c), myComp.LastIndexOf(myStr, "Æ"c))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c), myComp.LastIndexOf(myStr, "æ"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "AE", CompareOptions.Ordinal))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ae", CompareOptions.Ordinal))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.Ordinal))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "AE", CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ae", CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Æ"c, CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "æ"c, CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()
      Console.WriteLine("No options    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308)))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308)), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308)))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c), myComp.LastIndexOf(myStr, "Ü"c))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c), myComp.LastIndexOf(myStr, "ü"c))
      Console.WriteLine("Ordinal       : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.Ordinal))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.Ordinal))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.Ordinal), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}", myStr)
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "Ü"c, CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, CompareOptions.IgnoreCase), myComp.LastIndexOf(myStr, "ü"c, CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 
         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'No options    : Is AE or ae the same as Æ or æ?
'           AE :    f                    l
'           ae :          f                   l
'            Æ :    f                    l
'            æ :          f                   l
'Ordinal       : Is AE or ae the same as Æ or æ?
'           AE :    b
'           ae :          b
'            Æ :                         b
'            æ :                              b
'IgnoreCase    : Is AE or ae the same as Æ or æ?
'           AE :    f                         l
'           ae :    f                         l
'            Æ :    f                         l
'            æ :    f                         l
'
'No options    : Is U" or u" the same as Ü or ü?
'           U" :    f                    l
'           u" :          f                   l
'            Ü :    f                    l
'            ü :          f                   l
'Ordinal       : Is U" or u" the same as Ü or ü?
'           U" :    b
'           u" :          b
'            Ü :                         b
'            ü :                              b
'IgnoreCase    : Is U" or u" the same as Ü or ü?
'           U" :    f                         l
'           u" :    f                         l
'            Ü :    f                         l
'            ü :    f                         l

설명

원본 문자열은 문자열의 끝에서 시작하여 문자열의 시작 부분에서 끝나는 뒤로 검색됩니다.

이 오버로드는 문화권에 민감한 검색을 수행합니다. 합자 "Æ"(U+00C6)와 같이 미리 계산된 문자를 나타내는 유니코드 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같이 올바른 시퀀스에서 문자의 구성 요소가 나타나는 것과 동일한 것으로 간주될 수 있습니다. 유니코드 값을 비교하는 서수(문화권을 구분하지 않는) 검색을 수행하려면 형식 CompareOptions 매개 변수가 있는 오버로드 중 하나를 호출하고 값을 사용해야 CompareOptions.Ordinal 합니다.

참고

가능하면 형식 CompareOptions 의 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권 구분 검색에서는 value에 무시할 수 있는 문자가 포함된 경우 결과는 해당 문자가 제거된 대상을 검색하는 것과 같습니다. 하나 이상의 무시 가능한 문자로만 구성된 경우 value 메서드는 LastIndexOf(String, String) 항상 .를 반환합니다 source.Length - 1- 의 마지막 인덱스 위치를 source나타냅니다. 다음 예제 LastIndexOf(String, String) 에서는 이 메서드를 사용하여 두 문자열에서 세 개의 부분 문자열(소프트 하이픈(U+00AD), 소프트 하이픈, "n", 소프트 하이픈, "m"을 찾습니다. 문자열 중 하나에만 사용자 지정 하이픈이 포함되어 있습니다. 각각의 경우에서 소프트 하이픈은 무시할 수 있는 문자이므로 결과는 소프트 하이픈이 포함되지 value않은 경우와 같습니다. 소프트 하이픈만 검색하는 경우 메서드는 6과 5를 반환합니다. 이러한 값은 두 문자열의 마지막 문자 인덱스에 해당합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      // Find the index of the last soft hyphen.
      Console.WriteLine(ci.LastIndexOf(s1, "\u00AD"));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00AD"));

      // Find the index of the last soft hyphen followed by "n".
      Console.WriteLine(ci.LastIndexOf(s1, "\u00ADn"));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00ADn"));

      // Find the index of the last soft hyphen followed by "m".
      Console.WriteLine(ci.LastIndexOf(s1, "\u00ADm"));
      Console.WriteLine(ci.LastIndexOf(s2, "\u00ADm"));
   }
}
// The example displays the following output:
//       6
//       5
//       1
//       1
//       4
//       3

추가 정보

적용 대상

LastIndexOf(String, String, Int32)

소스 문자열 중 처음부터 지정된 인덱스까지의 영역에서 지정된 부분 문자열을 검색하고, 마지막에 검색된 항목의 인덱스(0부터 시작)를 반환합니다.

public:
 int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex);
public:
 virtual int LastIndexOf(System::String ^ source, System::String ^ value, int startIndex);
public int LastIndexOf (string source, string value, int startIndex);
public virtual int LastIndexOf (string source, string value, int startIndex);
member this.LastIndexOf : string * string * int -> int
abstract member LastIndexOf : string * string * int -> int
override this.LastIndexOf : string * string * int -> int
Public Function LastIndexOf (source As String, value As String, startIndex As Integer) As Integer
Public Overridable Function LastIndexOf (source As String, value As String, startIndex As Integer) As Integer

매개 변수

source
String

검색할 문자열입니다.

value
String

source에서 찾을 문자열입니다.

startIndex
Int32

역방향 검색의 0부터 시작하는 인덱스입니다.

반환

Int32

valuesource의 맨 앞부터 source까지의 영역에서 startIndex를 찾은 경우 마지막에 검색된 항목의 인덱스(0부터 시작)이고, 그렇지 않으면 -1입니다. startIndex가 무시할 수 있는 문자인 경우 value를 반환합니다.

예외

source이(가) null인 경우

또는

value이(가) null인 경우

startIndexsource의 유효한 인덱스 범위를 벗어납니다.

예제

다음 예제에서는 문자열의 일부 내에서 문자 또는 부분 문자열의 첫 번째 및 마지막 항목의 인덱스를 결정합니다. IndexOf LastIndexOf 동일한 startIndex 매개 변수를 사용하더라도 문자열의 여러 부분에서 검색하고 있습니다.

using namespace System;
using namespace System::Globalization;
void PrintMarker( String^ Prefix, int First, int Last )
{
   
   // Determines the size of the array to create.
   int mySize;
   if ( Last > First )
      mySize = Last;
   else
      mySize = First;

   if ( mySize > -1 )
   {
      
      // Creates an array of Char to hold the markers.
      array<Char>^myCharArr = gcnew array<Char>(mySize + 1);
      
      // Inserts the appropriate markers.
      if ( First > -1 )
            myCharArr[ First ] = 'f';
      if ( Last > -1 )
            myCharArr[ Last ] = 'l';
      if ( First == Last )
            myCharArr[ First ] = 'b';
      
      // Displays the array of Char as a String.
      Console::WriteLine( "{0}{1}", Prefix, gcnew String( myCharArr ) );
   }
   else
      Console::WriteLine( Prefix );
}

int main()
{
   
   // Creates CompareInfo for the InvariantCulture.
   CompareInfo^ myComp = CultureInfo::InvariantCulture->CompareInfo;
   
   // iS is the starting index of the substring.
   int iS = 20;
   
   // myT1 is the string used for padding.
   String^ myT1;
   
   // Searches for the ligature Æ.
   String^ myStr = "Is AE or ae the same as Æ or æ?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           AE : ", myComp->IndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           ae : ", myComp->IndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Æ : ", myComp->IndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            æ : ", myComp->IndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           AE : ", -1, myComp->LastIndexOf( myStr, "AE", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           ae : ", -1, myComp->LastIndexOf( myStr, "ae", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Æ : ", -1, myComp->LastIndexOf( myStr, L'Æ', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            æ : ", -1, myComp->LastIndexOf( myStr, L'æ', iS, CompareOptions::IgnoreCase ) );
   
   // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
   myStr = "Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   Console::WriteLine();
   myT1 = gcnew String( '-',iS );
   Console::WriteLine( "IndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS ), -1 );
   Console::WriteLine( "Ordinal       : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ), -1 );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr->Substring( iS ) );
   PrintMarker( "           U\u0308 : ", myComp->IndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "           u\u0308 : ", myComp->IndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            Ü : ", myComp->IndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ), -1 );
   PrintMarker( "            ü : ", myComp->IndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ), -1 );
   myT1 = gcnew String( '-',myStr->Length - iS - 1 );
   Console::WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
   Console::WriteLine( "Original      : {0}", myStr );
   Console::WriteLine( "No options    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS ) );
   Console::WriteLine( "Ordinal       : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::Ordinal ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::Ordinal ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::Ordinal ) );
   Console::WriteLine( "IgnoreCase    : {0}{1}", myStr->Substring( 0, iS + 1 ), myT1 );
   PrintMarker( "           U\u0308 : ", -1, myComp->LastIndexOf( myStr, "U\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "           u\u0308 : ", -1, myComp->LastIndexOf( myStr, "u\u0308", iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            Ü : ", -1, myComp->LastIndexOf( myStr, L'Ü', iS, CompareOptions::IgnoreCase ) );
   PrintMarker( "            ü : ", -1, myComp->LastIndexOf( myStr, L'ü', iS, CompareOptions::IgnoreCase ) );
}

/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Creates CompareInfo for the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // iS is the starting index of the substring.
      int iS = 20;
      // myT1 is the string used for padding.
      String myT1;

      // Searches for the ligature Æ.
      String myStr = "Is AE or ae the same as Æ or æ?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           AE : ", myComp.IndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           ae : ", myComp.IndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Æ : ", myComp.IndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            æ : ", myComp.IndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           AE : ", -1, myComp.LastIndexOf( myStr, "AE", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           ae : ", -1, myComp.LastIndexOf( myStr, "ae", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Æ : ", -1, myComp.LastIndexOf( myStr, 'Æ', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            æ : ", -1, myComp.LastIndexOf( myStr, 'æ', iS, CompareOptions.IgnoreCase ) );

      // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
      Console.WriteLine();

      myT1 = new String( '-', iS );
      Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS ), -1 );
      Console.WriteLine( "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ), -1 );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) );
      PrintMarker( "           U\u0308 : ", myComp.IndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "           u\u0308 : ", myComp.IndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            Ü : ", myComp.IndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ), -1 );
      PrintMarker( "            ü : ", myComp.IndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ), -1 );

      myT1 = new String( '-', myStr.Length - iS - 1 );
      Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
      Console.WriteLine( "Original      : {0}", myStr );
      Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS ) );
      Console.WriteLine( "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.Ordinal ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.Ordinal ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.Ordinal ) );
      Console.WriteLine( "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
      PrintMarker( "           U\u0308 : ", -1, myComp.LastIndexOf( myStr, "U\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "           u\u0308 : ", -1, myComp.LastIndexOf( myStr, "u\u0308", iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            Ü : ", -1, myComp.LastIndexOf( myStr, 'Ü', iS, CompareOptions.IgnoreCase ) );
      PrintMarker( "            ü : ", -1, myComp.LastIndexOf( myStr, 'ü', iS, CompareOptions.IgnoreCase ) );
   }

   public static void PrintMarker( String Prefix, int First, int Last )  {

      // Determines the size of the array to create.
      int mySize;
      if ( Last > First )
         mySize = Last;
      else
         mySize = First;

      if ( mySize > -1 )  {

         // Creates an array of Char to hold the markers.
         Char[] myCharArr = new Char[mySize+1];

         // Inserts the appropriate markers.
         if ( First > -1 )
         myCharArr[First] = 'f';
         if ( Last > -1 )
            myCharArr[Last] = 'l';
         if ( First == Last )
         myCharArr[First] = 'b';

         // Displays the array of Char as a String.
         Console.WriteLine( "{0}{1}", Prefix, new String( myCharArr ) );
      }
      else
        {
            Console.WriteLine( Prefix );
        }
    }
}


/*
This code produces the following output.

IndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : -------------------- as Æ or æ?
           AE :                         f
           ae :                              f
            Æ :                         f
            æ :                              f
Ordinal       : -------------------- as Æ or æ?
           AE :
           ae :
            Æ :                         f
            æ :                              f
IgnoreCase    : -------------------- as Æ or æ?
           AE :                         f
           ae :                         f
            Æ :                         f
            æ :                         f
LastIndexOf( String, *, 20, * )
Original      : Is AE or ae the same as Æ or æ?
No options    : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :    l
            æ :          l
Ordinal       : Is AE or ae the same ----------
           AE :    l
           ae :          l
            Æ :
            æ :
IgnoreCase    : Is AE or ae the same ----------
           AE :          l
           ae :          l
            Æ :          l
            æ :          l

IndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : -------------------- as Ü or ü?
           U" :                         f
           u" :                              f
            Ü :                         f
            ü :                              f
Ordinal       : -------------------- as Ü or ü?
           U" :
           u" :
            Ü :                         f
            ü :                              f
IgnoreCase    : -------------------- as Ü or ü?
           U" :                         f
           u" :                         f
            Ü :                         f
            ü :                         f
LastIndexOf( String, *, 20, * )
Original      : Is U" or u" the same as Ü or ü?
No options    : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :    l
            ü :          l
Ordinal       : Is U" or u" the same ----------
           U" :    l
           u" :          l
            Ü :
            ü :
IgnoreCase    : Is U" or u" the same ----------
           U" :          l
           u" :          l
            Ü :          l
            ü :          l

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Creates CompareInfo for the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' iS is the starting index of the substring.
      Dim [iS] As Integer = 20
      ' myT1 is the string used for padding.
      Dim myT1 As [String]

      ' Searches for the ligature Æ.
      Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS]), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS]), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS]), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS]))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS]))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS]))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.Ordinal))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.Ordinal))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           AE : ", - 1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase))
      PrintMarker("           ae : ", - 1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Æ : ", - 1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            æ : ", - 1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase))

      ' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
      myStr = "Is " & ChrW(&H0055) & ChrW(&H0308) & " or " & ChrW(&H0075) & ChrW(&H0308) & " the same as " & ChrW(&H00DC) & " or " & ChrW(&H00FC) & "?"
      Console.WriteLine()

      myT1 = New [String]("-"c, [iS])
      Console.WriteLine("IndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS]), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS]), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS]), - 1)
      Console.WriteLine("Ordinal       : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal), - 1)
      Console.WriteLine("IgnoreCase    : {0}{1}", myT1, myStr.Substring([iS]))
      PrintMarker("           U" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("           u" & ChrW(&H0308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase), - 1)
      PrintMarker("            ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase), - 1)

      myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
      Console.WriteLine("LastIndexOf( String, *, {0}, * )", [iS])
      Console.WriteLine("Original      : {0}", myStr)
      Console.WriteLine("No options    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS]))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS]))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS]))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS]))
      Console.WriteLine("Ordinal       : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.Ordinal))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal))
      Console.WriteLine("IgnoreCase    : {0}{1}", myStr.Substring(0, [iS] + 1), myT1)
      PrintMarker("           U" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "U" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("           u" & ChrW(&H0308) & " : ", - 1, myComp.LastIndexOf(myStr, "u" & ChrW(&H0308), [iS], CompareOptions.IgnoreCase))
      PrintMarker("            Ü : ", - 1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase))
      PrintMarker("            ü : ", - 1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase))

   End Sub

   Public Shared Sub PrintMarker(Prefix As [String], First As Integer, Last As Integer)

      ' Determines the size of the array to create.
      Dim mySize As Integer
      If Last > First Then
         mySize = Last
      Else
         mySize = First
      End If 

      If mySize > - 1 Then

         ' Creates an array of Char to hold the markers.
         Dim myCharArr(mySize + 1) As [Char]

         ' Inserts the appropriate markers.
         If First > - 1 Then
            myCharArr(First) = "f"c
         End If
         If Last > - 1 Then
            myCharArr(Last) = "l"c
         End If
         If First = Last Then
            myCharArr(First) = "b"c
         End If 

         ' Displays the array of Char as a String.
         Console.WriteLine("{0}{1}", Prefix, New [String](myCharArr))
      
      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


'This code produces the following output.
'
'IndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                              f
'            Æ :                         f
'            æ :                              f
'Ordinal       : -------------------- as Æ or æ?
'           AE :
'           ae :
'            Æ :                         f
'            æ :                              f
'IgnoreCase    : -------------------- as Æ or æ?
'           AE :                         f
'           ae :                         f
'            Æ :                         f
'            æ :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is AE or ae the same as Æ or æ?
'No options    : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :    l
'            æ :          l
'Ordinal       : Is AE or ae the same ----------
'           AE :    l
'           ae :          l
'            Æ :
'            æ :
'IgnoreCase    : Is AE or ae the same ----------
'           AE :          l
'           ae :          l
'            Æ :          l
'            æ :          l
'
'IndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                              f
'            Ü :                         f
'            ü :                              f
'Ordinal       : -------------------- as Ü or ü?
'           U" :
'           u" :
'            Ü :                         f
'            ü :                              f
'IgnoreCase    : -------------------- as Ü or ü?
'           U" :                         f
'           u" :                         f
'            Ü :                         f
'            ü :                         f
'LastIndexOf( String, *, 20, * )
'Original      : Is U" or u" the same as Ü or ü?
'No options    : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :    l
'            ü :          l
'Ordinal       : Is U" or u" the same ----------
'           U" :    l
'           u" :          l
'            Ü :
'            ü :
'IgnoreCase    : Is U" or u" the same ----------
'           U" :          l
'           u" :          l
'            Ü :          l
'            ü :          l

설명

원본 문자열은 문자열의 시작 부분에서 startIndex 시작하여 끝나는 뒤로 검색됩니다.

이 오버로드는 문화권에 민감한 검색을 수행합니다. 합자 "Æ"(U+00C6)와 같이 미리 컴파일된 문자를 나타내는 유니코드 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다. 유니코드 값이 비교되는 서수(문화권 구분 안 함) 검색을 수행하려면 형식 CompareOptions 매개 변수가 있는 오버로드 중 하나를 호출하고 값을 사용해야 CompareOptions.Ordinal 합니다.

참고

가능하면 형식 CompareOptions 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.Ordinal CompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

호출자 참고

문자 집합에는 언어 또는 문화권 구분 정렬을 수행할 때 고려되지 않는 문자인 무시 가능한 문자가 포함됩니다. 문화권 구분 검색에서는 value에 무시할 수 있는 문자가 포함된 경우 결과는 해당 문자가 제거된 대상을 검색하는 것과 같습니다. 하나 이상의 무시 가능한 문자로만 구성된 경우 value 메서드는 LastIndexOf(String, String, Int32) 항상 검색이 시작되는 문자 위치인 값을 반환 startIndex합니다. 다음 예제 LastIndexOf(String, String, Int32) 에서 메서드는 소프트 하이픈(U+00AD)을 포함하고 문자열에 마지막 "m"을 앞에 포함하거나 포함하는 부분 문자열을 찾는 데 사용됩니다. 검색 문자열의 소프트 하이픈은 무시되므로 메서드를 호출하여 소프트 하이픈과 "m"으로 구성된 부분 문자열을 찾으려면 문자열에서 "m"의 위치를 반환하는 반면, 소프트 하이픈과 "n"으로 구성된 부분 문자열을 찾으려면 호출하면 "n"의 위치가 반환됩니다. 검색 문자열에 소프트 하이픈만 포함된 경우 메서드는 값을 startIndex나타내는 "m"의 인덱스를 반환합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

      int position = 0;

      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      // Find the index of the soft hyphen.
      position = ci.LastIndexOf(s1, "m");
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, "\u00AD", position));

      position = ci.LastIndexOf(s2, "m");
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, "\u00AD", position));

      // Find the index of the soft hyphen followed by "n".
      position = ci.LastIndexOf(s1, "m");
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, "\u00ADn", position));

      position = ci.LastIndexOf(s2, "m");
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, "\u00ADn", position));

      // Find the index of the soft hyphen followed by "m".
      position = ci.LastIndexOf(s1, "m");
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s1, "\u00ADm", position));

      position = ci.LastIndexOf(s2, "m");
      Console.WriteLine("'m' at position {0}", position);
      if (position >= 0)
         Console.WriteLine(ci.LastIndexOf(s2, "\u00ADm", position));
   }
}
// The example displays the following output:
//       'm' at position 4
//       4
//       'm' at position 3
//       3
//       'm' at position 4
//       1
//       'm' at position 3
//       1
//       'm' at position 4
//       4
//       'm' at position 3
//       3

추가 정보

적용 대상