CompareInfo.LastIndexOf Метод

Определение

Возвращает отсчитываемый с нуля индекс последнего экземпляра значения в строке или в ее части.

Перегрузки

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

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего экземпляра в разделе строки источника, который содержит указанное количество элементов и заканчивается на указанном индексе, с использованием указанного значения CompareOptions.

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

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего экземпляра в разделе строки источника, который содержит указанное количество элементов и заканчивается на указанном индексе, с использованием указанного значения CompareOptions.

LastIndexOf(String, String, Int32, Int32)

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего экземпляра в части строки источника, который содержит указанное количество элементов и заканчивается на указанном индексе.

LastIndexOf(String, String, Int32, CompareOptions)

Осуществляет поиск заданной подстроки и возвращает отсчитываемый от нуля индекс последнего экземпляра в разделе исходной строки от начала строки до заданного индекса с использованием заданного значения CompareOptions.

LastIndexOf(String, Char, Int32, Int32)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего экземпляра в части строки источника, которая содержит указанное количество элементов и заканчивается на указанном индексе.

LastIndexOf(String, Char, Int32, CompareOptions)

Осуществляет поиск заданного знака и возвращает отсчитываемый от нуля индекс последнего экземпляра в разделе исходной строки от начала строки до заданного индекса с использованием заданного значения CompareOptions.

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

Выполняет поиск последнего вхождения подстроки в исходной строке.

LastIndexOf(String, Char)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего найденного экземпляра во всей строке источника.

LastIndexOf(String, String, CompareOptions)

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего найденного экземпляра во всей строке источника с использованием заданного значения CompareOptions.

LastIndexOf(String, Char, Int32)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего экземпляра в разделе строки источника от начала строки до указанного индекса.

LastIndexOf(String, Char, CompareOptions)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего найденного экземпляра во всей строке источника с использованием заданного значения CompareOptions.

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

Выполняет поиск последнего вхождения Rune в пределах указанного диапазона символов, доступного только для чтения.

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

Выполняет поиск последнего вхождения подстроки в пределах указанного диапазона символов, доступного только для чтения.

LastIndexOf(String, String)

Выполняет поиск указанной подстроки и возвращает начинающийся с нуля индекс последнего экземпляра в рамках всей исходной строки.

LastIndexOf(String, String, Int32)

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего экземпляра в части строки источника от начала строки до указанного индекса.

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

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего экземпляра в разделе строки источника, который содержит указанное количество элементов и заканчивается на указанном индексе, с использованием указанного значения CompareOptions.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

count
Int32

Число элементов в диапазоне, в котором выполняется поиск.

options
CompareOptions

Значение, определяющее способ сравнения source и value. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в разделе source, который содержит количество элементов, определяемое параметром count и заканчивается на startIndex, с использованием указанных параметров сравнения; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

-или-

value имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

-или-

Значение параметра count меньше нуля.

-или-

startIndex и count не указывают допустимый раздел в source.

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

Комментарии

Поиск в строке источника осуществляется в обратном направлении, начиная с startIndex startIndex - count + 1.

Значение недопустимо CompareOptions.StringSort для этого метода.

Если не options содержит Ordinal значение, эта перегрузка выполняет поиск с учетом языка и региональных параметров. Значение Юникода, представляющее составной символ, например лигатуру "Æ" (U + 00C6), может рассматриваться как эквивалент любого вхождения компонентов символа в правильной последовательности, например "AE" (U + 0041, U + 0045), в зависимости от языка и региональных параметров. Если options включает Ordinal значение, эта перегрузка выполняет поиск по порядковому номеру (без учета языка и региональных параметров), где сравниваются значения Юникода.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа, CompareOptions чтобы указать тип ожидаемого сравнения. В качестве общего правила используйте лингвистические параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

Примечания для тех, кто вызывает этот метод

Наборы символов содержат игнорируемые символы, которые не учитываются при выполнении лингвистической или учитывающей язык и региональные параметры сортировки. Если при поиске с учетом языка и региональных параметров (то есть, если параметр options не имеет значение Ordinal или OrdinalIgnoreCase) параметр value содержит игнорируемый символ, результат аналогичен поиску с удаленным этим символом. Если value состоит только из одного или нескольких игнорируемых символов, LastIndexOf(String, String, Int32, Int32, CompareOptions) метод всегда возвращает значение startIndex , которое является позицией символа, с которого начинается поиск.

В следующем примере LastIndexOf(String, String, Int32, Int32, CompareOptions) метод используется для поиска позиции мягкого дефиса (U + 00AD), за которым следует символ «m», кроме первого знака «m» в двух строках. Только одна из строк содержит требуемую подстроку. Поскольку мягкий перенос является игнорируемым символом, в обоих случаях при сравнении с учетом языка и региональных параметров метод возвращает индекс символа "m" в строке. Однако при выполнении порядкового сравнения он находит подстроку только в первой строке. Обратите внимание, что в случае первой строки, которая включает мягкий дефис, за которым следует символ "m", метод не возвращает индекс мягкого дефиса, а вместо этого возвращает индекс "m", когда он выполняет сравнение с учетом языка и региональных параметров. Этот метод возвращает индекс мягкого переноса в первой строке только при выполнении порядкового сравнения.

::: код Language = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable15.vb" ID = "Snippet16":::

См. также раздел

Применяется к

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

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего экземпляра в разделе строки источника, который содержит указанное количество элементов и заканчивается на указанном индексе, с использованием указанного значения CompareOptions.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

count
Int32

Число элементов в диапазоне, в котором выполняется поиск.

options
CompareOptions

Значение, определяющее способ сравнения source и value. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в разделе source, который содержит количество элементов, определяемое параметром count и заканчивается на startIndex, с использованием указанных параметров сравнения; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

-или-

Значение параметра count меньше нуля.

-или-

startIndex и count не указывают допустимый раздел в source.

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

Комментарии

Поиск в строке источника осуществляется в обратном направлении, начиная с startIndex startIndex - count + 1.

Значение недопустимо CompareOptions.StringSort для этого метода.

Если не options содержит Ordinal значение, эта перегрузка выполняет поиск с учетом языка и региональных параметров. Если символ является значением Юникода, представляющим собой составной символ, такой как лигатура "Æ" (U + 00C6), он может считаться эквивалентом любого вхождения его компонентов в правильной последовательности, например "AE" (U + 0041, U + 0045), в зависимости от языка и региональных параметров. Если options включает Ordinal значение, эта перегрузка выполняет поиск по порядковому номеру (без учета языка и региональных параметров). Символ считается эквивалентным другому символу только в том случае, если значения Юникода одинаковы. Перегрузки String.LastIndexOf , используемые для поиска символа, выполняют порядковый поиск, тогда как поиск строки выполняется с учетом языка и региональных параметров.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа, CompareOptions чтобы указать тип ожидаемого сравнения. В качестве общего правила используйте лингвистические параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

Примечания для тех, кто вызывает этот метод

Наборы символов содержат игнорируемые символы, которые не учитываются при выполнении лингвистической или учитывающей язык и региональные параметры сортировки. При поиске с учетом языка и региональных параметров, если value является игнорируемым символом, результат эквивалентен поиску с удалением этого символа. В этом случае LastIndexOf(String, Char, Int32, Int32, CompareOptions) метод всегда возвращает значение startIndex , которое является позицией символа, с которого начинается поиск. В следующем примере LastIndexOf(String, Char, Int32, Int32, CompareOptions) метод используется для поиска мягкого дефиса (U + 00AD), предшествующего завершающему символу «m» в двух строках. Только одна из строк содержит мягкий перенос. В обоих случаях, поскольку мягкий дефис является игнорируемым символом, поиск с учетом языка и региональных параметров возвращает индекс "m", который является значением startIndex . Однако порядковый поиск по порядковому номеру успешно находит мягкий дефис в одной строке и сообщает, что он отсутствует во второй строке.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable11.cs" ID = "Snippet12":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable11.vb" ID = "Snippet12":::

См. также раздел

Применяется к

LastIndexOf(String, String, Int32, Int32)

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего экземпляра в части строки источника, который содержит указанное количество элементов и заканчивается на указанном индексе.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

count
Int32

Число элементов в диапазоне, в котором выполняется поиск.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего экземпляра value, если есть, в разделе source, который содержит количество элементов, определяемое параметром count заканчивается на startIndex; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

-или-

value имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

-или-

Значение параметра count меньше нуля.

-или-

startIndex и count не указывают допустимый раздел в source.

Примеры

В следующем примере определяются индексы первого и последнего вхождений символа или подстроки в части строки.

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

Комментарии

Поиск в строке источника осуществляется в обратном направлении, начиная с startIndex startIndex - count + 1.

Эта перегрузка выполняет поиск с учетом языка и региональных параметров. Значение Юникода, представляющее составной символ, например лигатуру "Æ" (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".

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable16.cs" ID = "Snippet17":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable16.vb" ID = "Snippet17":::

См. также раздел

Применяется к

LastIndexOf(String, String, Int32, CompareOptions)

Осуществляет поиск заданной подстроки и возвращает отсчитываемый от нуля индекс последнего экземпляра в разделе исходной строки от начала строки до заданного индекса с использованием заданного значения CompareOptions.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

options
CompareOptions

Значение, определяющее способ сравнения source и value. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в разделе source, начиная с source и заканчивая startIndex, с использованием указанных параметров сравнения; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

-или-

value имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

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), в зависимости от языка и региональных параметров. Если options включает Ordinal значение, эта перегрузка выполняет поиск по порядковому номеру (без учета языка и региональных параметров), где сравниваются значения Юникода.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа, CompareOptions чтобы указать тип ожидаемого сравнения. В качестве общего правила используйте лингвистические параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

Примечания для тех, кто вызывает этот метод

Наборы символов содержат игнорируемые символы, которые не учитываются при выполнении лингвистической или учитывающей язык и региональные параметры сортировки. Если при поиске с учетом языка и региональных параметров (то есть, если параметр options не имеет значение Ordinal или OrdinalIgnoreCase) параметр value содержит игнорируемый символ, результат аналогичен поиску с удаленным этим символом. Если value состоит только из одного или нескольких игнорируемых символов, LastIndexOf(String, String, Int32, CompareOptions) метод всегда возвращает значение startIndex , которое является позицией символа, с которого начинается поиск.

В следующем примере LastIndexOf(String, String, Int32, CompareOptions) метод используется для поиска положения мягкого дефиса (U + 00AD), за которым следует символ "m", начиная с последнего "m" в двух строках. Только одна из строк содержит требуемую подстроку. Поскольку мягкий перенос является игнорируемым символом, в обоих случаях при сравнении с учетом языка и региональных параметров метод возвращает индекс символа "m" в строке. Обратите внимание, что в случае первой строки, содержащей мягкий перенос перед буквой "m", этот метод возвращает не индекс мягкого переноса, а индекс буквы "m". Этот метод возвращает индекс мягкого переноса в первой строке только при выполнении порядкового сравнения.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable14.cs" ID = "Snippet15":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable14.vb" ID = "Snippet15":::

См. также раздел

Применяется к

LastIndexOf(String, Char, Int32, Int32)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего экземпляра в части строки источника, которая содержит указанное количество элементов и заканчивается на указанном индексе.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

count
Int32

Число элементов в диапазоне, в котором выполняется поиск.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего экземпляра value, если есть, в разделе source, который содержит количество элементов, определяемое параметром count заканчивается на startIndex; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

-или-

Значение параметра count меньше нуля.

-или-

startIndex и count не указывают допустимый раздел в source.

Примеры

В следующем примере определяются индексы первого и последнего вхождений символа или подстроки в части строки.

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

Комментарии

Поиск в строке источника осуществляется в обратном направлении, начиная с startIndex startIndex - count + 1.

Эта перегрузка выполняет поиск с учетом языка и региональных параметров. Если символ является значением Юникода, представляющим собой составной символ, такой как лигатура "Æ" (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) метод используется для поиска мягкого дефиса (U + 00AD), предшествующего завершающему символу «m» в двух строках. Только одна из строк содержит мягкий перенос. В обоих случаях, поскольку мягкий дефис является игнорируемым символом, метод возвращает позиции индекса "m", которая является значением startIndex .

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable8.cs" ID = "Snippet9":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable8.vb" ID = "Snippet9":::

См. также раздел

Применяется к

LastIndexOf(String, Char, Int32, CompareOptions)

Осуществляет поиск заданного знака и возвращает отсчитываемый от нуля индекс последнего экземпляра в разделе исходной строки от начала строки до заданного индекса с использованием заданного значения CompareOptions.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

options
CompareOptions

Значение, определяющее способ сравнения source и value. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в разделе source, начиная с source и заканчивая startIndex, с использованием указанных параметров сравнения; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

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), в зависимости от языка и региональных параметров. Если options включает Ordinal значение, эта перегрузка выполняет поиск по порядковому номеру (без учета языка и региональных параметров). Символ считается эквивалентным другому символу только в том случае, если значения Юникода одинаковы. Перегрузки String.LastIndexOf , используемые для поиска символа, выполняют порядковый поиск, тогда как поиск строки выполняется с учетом языка и региональных параметров.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа, CompareOptions чтобы указать тип ожидаемого сравнения. В качестве общего правила используйте лингвистические параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

Примечания для тех, кто вызывает этот метод

Наборы символов содержат игнорируемые символы, которые не учитываются при выполнении лингвистической или учитывающей язык и региональные параметры сортировки. При поиске с учетом языка и региональных параметров, если value является игнорируемым символом, результат эквивалентен поиску с удалением этого символа. В этом случае LastIndexOf(String, Char, Int32, CompareOptions) метод всегда возвращает значение startIndex , которое является позицией символа, с которого начинается поиск. В следующем примере LastIndexOf(String, Char, Int32, CompareOptions) метод используется для поиска мягкого дефиса (U + 00AD), предшествующего завершающему символу «m» в двух строках. Только одна из строк содержит мягкий перенос. В обоих случаях, поскольку мягкий дефис является игнорируемым символом, поиск с учетом языка и региональных параметров возвращает индекс "m". Однако порядковый поиск по порядковому номеру успешно находит мягкий дефис в одной строке и сообщает, что он отсутствует во второй строке.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable7.cs" ID = "Snippet8":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable7.vb" ID = "Snippet8":::

См. также раздел

Применяется к

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 длину, если было выполнено лингвистическое сравнение. Задайте значение 0, если value не найдено в source.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс в source, по которому обнаружено последнее вхождение подстроки value; или отрицательное число, если value не удается найти в source.

Исключения

options содержит неподдерживаемое сочетание флагов.

Комментарии

Этот метод имеет больше издержек, чем другие LastIndexOf перегрузки, которые не принимают matchLength аргумент. Вызывайте эту перегрузку только в том случае, если требуются сведения о длине соответствия.

Применяется к

LastIndexOf(String, Char)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего найденного экземпляра во всей строке источника.

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; если не найден — значение -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) в двух строках. Только одна из строк содержит мягкий перенос. В обоих случаях, поскольку мягкий дефис является проигнорированным, метод возвращает последнюю позиции индекса в строке, чтобы показать, что в конце строки обнаружено совпадение.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable2.cs" ID = "Snippet3":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable2.vb" ID = "Snippet3":::

См. также раздел

Применяется к

LastIndexOf(String, String, CompareOptions)

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего найденного экземпляра во всей строке источника с использованием заданного значения CompareOptions.

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

Значение, определяющее способ сравнения source и value. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в source с использованием указанных параметров сравнения; в противном случае — значение -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), в зависимости от языка и региональных параметров. Если options включает Ordinal значение, эта перегрузка выполняет поиск по порядковому номеру (без учета языка и региональных параметров), где сравниваются значения Юникода.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа, CompareOptions чтобы указать тип ожидаемого сравнения. В качестве общего правила используйте лингвистические параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

Примечания для тех, кто вызывает этот метод

Наборы символов содержат игнорируемые символы, которые не учитываются при выполнении лингвистической или учитывающей язык и региональные параметры сортировки. Если при поиске с учетом языка и региональных параметров (то есть, если параметр options не имеет значение Ordinal или OrdinalIgnoreCase) параметр value содержит игнорируемый символ, результат аналогичен поиску с удаленным этим символом. Если value состоит только из одного или нескольких игнорируемых символов, LastIndexOf(String, String, CompareOptions) метод всегда возвращает значение source .Length значение-1, которое представляет последнюю позиции индекса в source . В следующем примере LastIndexOf(String, String, CompareOptions) метод используется для поиска трех подстрок (мягкий дефис (U + 00AD), мягкий дефис, за которым следует "n", и мягкий дефис, за которым следует "m") в двух строках. Только одна из строк содержит мягкий перенос. Поскольку мягкий дефис является игнорируемым символом, поиск с учетом языка и региональных параметров возвращает то же значение, которое возвращается, если мягкий дефис не был включен в строку поиска. Однако порядковый поиск по порядковому номеру успешно находит мягкий дефис в одной строке и сообщает, что он отсутствует во второй строке.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable5.cs" ID = "Snippet6":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable5.vb" ID = "Snippet6":::

См. также раздел

Применяется к

LastIndexOf(String, Char, Int32)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего экземпляра в разделе строки источника от начала строки до указанного индекса.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в разделе source, который начинается с source и заканчивается на startIndex; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

Примеры

В следующем примере определяются индексы первого и последнего вхождений символа или подстроки в части строки. Обратите внимание, что 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) метод используется для поиска мягкого дефиса (U + 00AD), предшествующего завершающему символу «m» в двух строках. Только одна из строк содержит мягкий перенос. В обоих случаях, поскольку мягкий дефис является игнорируемым символом, метод возвращает позиции индекса "m", которая является значением startIndex .

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable4.cs" ID = "Snippet5":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable4.vb" ID = "Snippet5":::

См. также раздел

Применяется к

LastIndexOf(String, Char, CompareOptions)

Осуществляет поиск указанного знака и возвращает отсчитываемый с нуля индекс последнего найденного экземпляра во всей строке источника с использованием заданного значения CompareOptions.

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

Значение, определяющее способ сравнения source и value. Параметр options является значением перечисления Ordinal, используемым самостоятельно, или побитовой комбинацией одного или нескольких следующих значений: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth и IgnoreKanaType.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в source с использованием указанных параметров сравнения; в противном случае — значение -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), в зависимости от языка и региональных параметров. Если options включает Ordinal значение, эта перегрузка выполняет поиск по порядковому номеру (без учета языка и региональных параметров). Символ считается эквивалентным другому символу только в том случае, если значения Юникода одинаковы. Перегрузки String.LastIndexOf , используемые для поиска символа, выполняют порядковый поиск, тогда как поиск строки выполняется с учетом языка и региональных параметров.

Примечание

По возможности следует вызывать методы сравнения строк, имеющие параметр типа, CompareOptions чтобы указать тип ожидаемого сравнения. В качестве общего правила используйте лингвистические параметры (с использованием текущего языка и региональных параметров) для сравнения строк, отображаемых в пользовательском интерфейсе, и укажите CompareOptions.Ordinal или CompareOptions.OrdinalIgnoreCase для сравнения безопасности.

Примечания для тех, кто вызывает этот метод

Наборы символов содержат игнорируемые символы, которые не учитываются при выполнении лингвистической или учитывающей язык и региональные параметры сортировки. При поиске с учетом языка и региональных параметров, если value является игнорируемым символом, результат эквивалентен поиску с удалением этого символа. В этом случае LastIndexOf(String, Char, CompareOptions) метод всегда возвращает место последнего символа в source , чтобы указать, что совпадение находится в конце source . В следующем примере LastIndexOf(String, Char, CompareOptions) метод используется для поиска мягкого дефиса (U + 00AD) в двух строках. Только одна из строк содержит мягкий перенос. В обоих случаях, поскольку мягкий дефис является игнорируемым символом, поиск с учетом языка и региональных параметров возвращает последнее значение индекса в исходной строке. В отличие от этого, порядковый поиск успешно находит мягкий дефис в одной строке и сообщает, что он отсутствует во второй строке.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable3.cs" ID = "Snippet4":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable3.vb" ID = "Snippet4":::

См. также раздел

Применяется к

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

Rune для поиска в source.

options
CompareOptions

Необязательное сочетание значений перечисления CompareOptions, используемое во время поиска. Значение по умолчанию — None.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс в source, по которому обнаружено последнее вхождение value; или отрицательное значение, если value не удается найти в source.

Исключения

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

Отсчитываемый от нуля индекс в source, по которому обнаружено последнее вхождение подстроки value; или отрицательное значение, если value не удается найти в source.

Исключения

options содержит неподдерживаемое сочетание флагов.

Применяется к

LastIndexOf(String, String)

Выполняет поиск указанной подстроки и возвращает начинающийся с нуля индекс последнего экземпляра в рамках всей исходной строки.

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; если не найден — значение -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. Эти значения соответствуют индексу последнего символа в двух строках.

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable1.cs" ID = "Snippet2":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable1.vb" ID = "Snippet2":::

См. также раздел

Применяется к

LastIndexOf(String, String, Int32)

Осуществляет поиск указанной подстроки и возвращает отсчитываемый с нуля индекс последнего экземпляра в части строки источника от начала строки до указанного индекса.

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

Индекс (с нуля) начала диапазона поиска в обратном направлении.

Возвращаемое значение

Int32

Отсчитываемый от нуля индекс последнего вхождения параметра value, если есть, в разделе source, который начинается с source и заканчивается на startIndex; в противном случае — значение -1. Возвращает startIndex, если value — игнорируемый символ.

Исключения

source имеет значение null.

-или-

value имеет значение null.

startIndex находится вне диапазона допустимых индексов для source.

Примеры

В следующем примере определяются индексы первого и последнего вхождений символа или подстроки в части строки. Обратите внимание, что 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". Если строка поиска содержит только мягкий дефис, метод возвращает индекс "m", который представляет значение startIndex .

::: код Language = "CSharp" Source = "~/samples/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable6.cs" ID = "Snippet7":::::: код языка = "VB" Source = "~/самплес/сниппетс/висуалбасик/VS_Snippets_CLR_System/System.Globalization.CompareInfo.LastIndexOf/VB/lastignorable6.vb" ID = "Snippet7":::

См. также раздел

Применяется к