CompareInfo.LastIndexOf メソッド

定義

文字列または部分文字列内にある値のうち、最後に出現する値の、0 から始まるインデックス番号を返します。

オーバーロード

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

指定した CompareOptions 値を使用して、指定した部分文字列を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

指定した CompareOptions 値を使用して、指定した文字を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, String, Int32, Int32)

指定した部分文字列を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, String, Int32, CompareOptions)

指定した CompareOptions 値を使用して、指定した部分文字列を検索し、検索対象の文字列の先頭から指定したインデックスまでの範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, Char, Int32, Int32)

指定した文字を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, Char, Int32, CompareOptions)

指定した CompareOptions 値を使用して、指定した文字を検索し、検索対象の文字列の先頭から指定したインデックスまでの範囲内で、その文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

ソース文字列内での部分文字列の最後の出現を検索します。

LastIndexOf(String, Char)

指定した文字を検索し、検索対象文字列全体内でその文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, String, CompareOptions)

指定した CompareOptions 値を使用して、指定した部分文字列を検索し、検索対象文字列全体内でその部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, Char, Int32)

指定した文字を検索し、検索対象文字列の先頭から指定したインデックスまでの範囲内で、その文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, Char, CompareOptions)

指定した CompareOptions 値を使用して、指定した文字を検索し、検索対象文字列全体内でその文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(ReadOnlySpan<Char>, Rune, CompareOptions)

指定の読み取り専用文字スパン内で最後に現れる Rune を検索します。

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

指定の読み取り専用文字スパン内で最後に現れる部分文字列を検索します。

LastIndexOf(String, String)

指定した部分文字列を検索し、検索対象文字列全体内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

LastIndexOf(String, String, Int32)

指定した部分文字列を検索し、検索対象文字列の先頭から指定したインデックスまでの範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

指定した CompareOptions 値を使用して、指定した部分文字列を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
String

source 内で検索する文字列。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

count
Int32

検索対象の範囲内にある要素の数。

options
CompareOptions

sourcevalue の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Int32

指定した比較オプションを使用して、startIndex で終わり、count で指定した数の要素を含んでいる source の範囲内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

または

valuenullです。

startIndexsource の有効なインデックスの範囲外です。

または

count が 0 未満です。

または

startIndex および countsource 内の有効なセクションを指定していません。

options に無効な CompareOptions 値が含まれています。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、+ 1 で startIndex 始まり、終わる startIndex - count 後方で検索されます。

このメソッドの CompareOptions.StringSort 値は無効です。

値がOrdinal含まれていない場合options、このオーバーロードはカルチャに依存する検索を実行します。 合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値は、カルチャによっては、"AE" (U+0041、U+0045) などの正しいシーケンスで文字のコンポーネントが発生した場合と同等と見なされる場合があります。 値がOrdinal含まれている場合options、このオーバーロードは序数 (カルチャに依存しない) 検索を実行します。ここで、Unicode 値が比較されます。

注意

可能であれば、予期される比較の種類を指定する型 CompareOptions のパラメーターを持つ文字列比較メソッドを呼び出す必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索の場合 (つまり、optionsOrdinal または OrdinalIgnoreCase でない場合)、value に無視できる文字が含まれていると、その文字を削除して検索した場合と同じ結果になります。 1 つ以上の無視可能な文字のみで構成されている場合 valueLastIndexOf(String, String, Int32, Int32, CompareOptions) メソッドは常に検索の開始位置である文字位置を返 startIndexします。

次の例では、このメソッドを使用して、 LastIndexOf(String, String, Int32, Int32, CompareOptions) ソフト ハイフン (U+ 00AD) の位置と、最後の "m" の前の最初の文字位置以外の "m" を 2 つの文字列で検索します。 文字列の 1 つのみに必要な部分文字列が含まれます。 どちらの場合も、ソフト ハイフンは無視可能な文字であるため、メソッドは、カルチャに依存した比較を実行すると、文字列に含まれる "m" のインデックスを返します。 ただし、序数比較を実行すると、最初の文字列内でのみ部分文字列が検索されます。 ソフト ハイフンの後に "m" が続く最初の文字列の場合、メソッドはソフト ハイフンのインデックスを返しませんが、カルチャに依存する比較を実行するときに "m" のインデックスを返します。 このメソッドは、序数に基づく比較を実行したときのみ、最初の文字列に含まれるソフト ハイフンのインデックスを返します。

::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable15.vb" id="Snippet16"::

こちらもご覧ください

適用対象

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

指定した CompareOptions 値を使用して、指定した文字を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
Char

source 内で検索する文字。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

count
Int32

検索対象の範囲内にある要素の数。

options
CompareOptions

sourcevalue の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Int32

指定した比較オプションを使用して、startIndex で終わり、count で指定した数の要素を含んでいる source の範囲内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

startIndexsource の有効なインデックスの範囲外です。

または

count が 0 未満です。

または

startIndex および countsource 内の有効なセクションを指定していません。

options に無効な CompareOptions 値が含まれています。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、+ 1 から startIndex 始まり、末尾 startIndex - count に戻って検索されます。

このメソッドの CompareOptions.StringSort 値は無効です。

値がOrdinal含まれていない場合options、このオーバーロードはカルチャに依存する検索を実行します。 文字が合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値の場合は、カルチャに応じて、正しいシーケンス ("AE" (U+0041、U+0045) などの正しいシーケンス内のコンポーネントの出現と同等と見なされる可能性があります。 値がOrdinal含まれている場合options、このオーバーロードは序数 (カルチャに依存しない) 検索を実行します。 文字は、Unicode 値が同じ場合にのみ、別の文字と同等と見なされます。 文字検索の String.LastIndexOf オーバーロードは序数検索を実行し、文字列を検索するオーバーロードはカルチャに依存する検索を実行します。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索では、無視できる文字の場合 value 、結果はその文字を削除した検索と同じです。 この場合、メソッドは LastIndexOf(String, Char, Int32, Int32, CompareOptions) 常に、検索の開始位置である文字位置を返 startIndexします。 次の例では、このメソッドを使用して、 LastIndexOf(String, Char, Int32, Int32, CompareOptions) 最後の "m" の前にあるソフト ハイフン (U+00AD) を 2 つの文字列で検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 どちらの場合も、ソフト ハイフンは無視できる文字であるため、カルチャに依存する検索では、"m" のインデックス位置が返されます。これは 、 の値 startIndexです。 ただし、序数検索では、1 つの文字列でソフト ハイフンが正常に検出され、2 番目の文字列に含まれていないことが報告されます。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable11.cs" id="Snippet12"::::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable11.vb" id="Snippet12"::

こちらもご覧ください

適用対象

LastIndexOf(String, String, Int32, Int32)

指定した部分文字列を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
String

source 内で検索する文字列。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

count
Int32

検索対象の範囲内にある要素の数。

戻り値

Int32

startIndex で終わり、count で指定した数の要素を含んでいる source の範囲内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

または

valuenullです。

startIndexsource の有効なインデックスの範囲外です。

または

count が 0 未満です。

または

startIndex および countsource 内の有効なセクションを指定していません。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、+ 1 から startIndex 始まり、末尾 startIndex - count に戻って検索されます。

このオーバーロードは、カルチャに依存する検索を実行します。 合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値は、カルチャによっては、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。 Unicode 値が比較される序数 (カルチャに依存しない) 検索を実行するには、型 CompareOptions のパラメーターを持つオーバーロードのいずれかを呼び出し、値を使用する Ordinal 必要があります。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存した検索では、value に無視できる文字が含まれている場合、その文字を削除して検索した場合と同じ結果になります。 1 つ以上の無視可能な文字のみで構成されている場合 valueLastIndexOf(String, String, Int32, Int32) メソッドは常に検索の開始位置である文字位置を返 startIndexします。

次の例では、このメソッドを使用して、 LastIndexOf(String, String, Int32, Int32) ソフト ハイフン (U+00AD) の位置と、2 つの文字列の最後の "m" の前にある 3 文字の "m" を検索します。 文字列の 1 つのみに必要な部分文字列が含まれます。 どちらの場合も、ソフト ハイフンは無視可能な文字であるため、メソッドは、カルチャに依存した比較を実行すると、文字列に含まれる "m" のインデックスを返します。 "m" の後にソフト ハイフンが含まれる最初の文字列の場合、メソッドはソフト ハイフンのインデックスを返すことができず、代わりに "m" のインデックスを返すことに注意してください。

using System;
using System.Globalization;

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

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

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

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

こちらもご覧ください

適用対象

LastIndexOf(String, String, Int32, CompareOptions)

指定した CompareOptions 値を使用して、指定した部分文字列を検索し、検索対象の文字列の先頭から指定したインデックスまでの範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
String

source 内で検索する文字列。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

options
CompareOptions

sourcevalue の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Int32

指定した比較オプションを使用して、source の先頭から startIndex までの source の範囲内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

または

valuenullです。

startIndexsource の有効なインデックスの範囲外です。

options に無効な CompareOptions 値が含まれています。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。 IndexOf LastIndexOf同じstartIndexパラメーターを使用しても、文字列のさまざまな部分で検索されていることに注意してください。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、文字列の startIndex 先頭から始まり、先頭から後方に検索されます。

このメソッドの CompareOptions.StringSort 値は無効です。

値がOrdinal含まれていない場合options、このオーバーロードはカルチャに依存する検索を実行します。 合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値は、カルチャによっては、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。 値がOrdinal含まれている場合options、このオーバーロードは序数 (カルチャを区別しない) 検索を実行します。ここで、Unicode 値が比較されます。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索の場合 (つまり、optionsOrdinal または OrdinalIgnoreCase でない場合)、value に無視できる文字が含まれていると、その文字を削除して検索した場合と同じ結果になります。 1 つ以上の無視可能な文字のみで構成されている場合 valueLastIndexOf(String, String, Int32, CompareOptions) メソッドは常に検索の開始位置である文字位置を返 startIndexします。

次の例では、このメソッドを使用して、 LastIndexOf(String, String, Int32, CompareOptions) ソフト ハイフン (U+00AD) の後に "m" が続く位置を、2 つの文字列の最後の "m" から検索します。 文字列の 1 つのみに必要な部分文字列が含まれます。 どちらの場合も、ソフト ハイフンは無視可能な文字であるため、メソッドは、カルチャに依存した比較を実行すると、文字列に含まれる "m" のインデックスを返します。 "m" の後にソフト ハイフンが含まれる最初の文字列の場合、メソッドはソフト ハイフンのインデックスを返すことができず、代わりに "m" のインデックスを返すことに注意してください。 このメソッドは、序数に基づく比較を実行したときのみ、最初の文字列に含まれるソフト ハイフンのインデックスを返します。

using System;
using System.Globalization;

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

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

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

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

こちらもご覧ください

適用対象

LastIndexOf(String, Char, Int32, Int32)

指定した文字を検索し、検索対象文字列の指定したインデックスで終了し、指定した数の要素を含んでいる範囲内で、その文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
Char

source 内で検索する文字。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

count
Int32

検索対象の範囲内にある要素の数。

戻り値

Int32

startIndex で終わり、count で指定した数の要素を含んでいる source の範囲内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

startIndexsource の有効なインデックスの範囲外です。

または

count が 0 未満です。

または

startIndex および countsource 内の有効なセクションを指定していません。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      Else
         Console.WriteLine(Prefix)

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、+ 1 から startIndex 始まり、末尾 startIndex - count に戻って検索されます。

このオーバーロードは、カルチャに依存する検索を実行します。 文字が合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値の場合は、カルチャに応じて、正しいシーケンス ("AE" (U+0041、U+0045) などの正しいシーケンス内のコンポーネントの出現と同等と見なされる可能性があります。 Unicode 値が同じ場合にのみ文字が別の文字と等価であると見なされる序数 (カルチャを区別しない) 検索を実行するには、型 CompareOptions のパラメーターを持ついずれかのオーバーロードを呼び出し、その値を使用する Ordinal 必要があります。 文字検索の String.LastIndexOf オーバーロードは序数検索を実行し、文字列を検索するオーバーロードはカルチャに依存する検索を実行します。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索では、無視できる文字の場合 value 、結果はその文字を削除した検索と同じです。 この場合、メソッドは LastIndexOf(String, Char, Int32, Int32) 常に検索の startIndex開始位置である文字位置を返します。 次の例では、このメソッドを LastIndexOf(String, Char, Int32, Int32) 使用して、2 つの文字列の最後の "m" の前にあるソフト ハイフン (U+00AD) を検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 どちらの場合も、ソフト ハイフンは無視可能な文字であるため、メソッドは "m" のインデックス位置を返します。この値 startIndexは .

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable8.cs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable8.vb" id="Snippet9":::

こちらもご覧ください

適用対象

LastIndexOf(String, Char, Int32, CompareOptions)

指定した CompareOptions 値を使用して、指定した文字を検索し、検索対象の文字列の先頭から指定したインデックスまでの範囲内で、その文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
Char

source 内で検索する文字。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

options
CompareOptions

sourcevalue の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Int32

指定した比較オプションを使用して、source の先頭から startIndex までの source の範囲内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

startIndexsource の有効なインデックスの範囲外です。

options に無効な CompareOptions 値が含まれています。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。 IndexOf LastIndexOf同じstartIndexパラメーターを使用しても、文字列のさまざまな部分で検索されていることに注意してください。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、文字列の startIndex 先頭から始まり、先頭から後方に検索されます。

このメソッドの CompareOptions.StringSort 値は無効です。

値がOrdinal含まれていない場合options、このオーバーロードはカルチャに依存する検索を実行します。 文字が合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値の場合は、カルチャに応じて、正しいシーケンス ("AE" (U+0041、U+0045) などの正しいシーケンス内のコンポーネントの出現と同等と見なされる可能性があります。 値がOrdinal含まれている場合options、このオーバーロードは序数 (カルチャに依存しない) 検索を実行します。 文字は、Unicode 値が同じ場合にのみ、別の文字と同等と見なされます。 文字検索の String.LastIndexOf オーバーロードは序数検索を実行し、文字列を検索するオーバーロードはカルチャに依存する検索を実行します。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索では、無視できる文字の場合 value 、結果はその文字を削除した検索と同じです。 この場合、メソッドは LastIndexOf(String, Char, Int32, CompareOptions) 常に検索の startIndex開始位置である文字位置を返します。 次の例では、このメソッドを LastIndexOf(String, Char, Int32, CompareOptions) 使用して、2 つの文字列の最後の "m" の前にあるソフト ハイフン (U+00AD) を検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 どちらの場合も、ソフト ハイフンは無視できる文字であるため、カルチャに依存する検索では "m" のインデックス位置が返されます。 ただし、序数検索では、1 つの文字列でソフト ハイフンが正常に検出され、2 番目の文字列に含まれていないことが報告されます。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable7.cs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/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 の長さとは異なることがあります。 source 内に value が見つからない場合は 0 に設定されます。

戻り値

Int32

部分文字列 value が最後に現れる source のゼロから始まるインデックス番号。あるいは、source 内で value が見つからない場合は負の数字。

例外

options には、サポートされていない組み合わせのフラグが含まれています。

注釈

このメソッドは、引数を受け取matchLengthらない他LastIndexOfのオーバーロードよりもオーバーヘッドが大きくなります。 このオーバーロードは、一致する長さの情報が必要な場合にのみ呼び出します。

適用対象

LastIndexOf(String, Char)

指定した文字を検索し、検索対象文字列全体内でその文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
Char

source 内で検索する文字。

戻り値

Int32

source 内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。

例外

sourcenullです。

次の例では、文字列内の文字または部分文字列の最初と最後の出現のインデックスを決定します。

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) などの事前計算済み文字を表す Unicode 値の場合は、カルチャに応じて、正しいシーケンス ("AE" (U+0041、U+0045) などの正しいシーケンス内のコンポーネントの出現と同等と見なされる可能性があります。 Unicode 値が同じ場合にのみ文字が別の文字と等価と見なされる序数 (カルチャに依存しない) 検索を実行するには、型 CompareOptions のパラメーターを持つオーバーロードのいずれかを呼び出し、値を使用する Ordinal 必要があります。 文字の検索の String.LastIndexOf オーバーロードは序数検索を実行しますが、文字列を検索する場合はカルチャに依存する検索を実行します。

注意

可能であれば、予期される比較の種類を指定する型 CompareOptions のパラメーターを持つ文字列比較メソッドを呼び出す必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索では、無視できる文字の場合 value 、結果はその文字を削除した検索と同じです。 この場合、メソッドは LastIndexOf(String, Char) 常に最後のインデックス位置 source を返して、最後に一致が見つかった sourceことを示します。 次の例では、このメソッドを LastIndexOf(String, Char) 使用して、2 つの文字列でソフト ハイフン (U+00AD) を検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 どちらの場合も、ソフト ハイフンは無視できる文字であるため、メソッドは文字列の最後のインデックス位置を返して、文字列の末尾に一致が見つかったことを示します。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable2.cs" id="Snippet3":::::code language="vb" source="::::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable2.vb" id="Snippet3::

こちらもご覧ください

適用対象

LastIndexOf(String, String, CompareOptions)

指定した CompareOptions 値を使用して、指定した部分文字列を検索し、検索対象文字列全体内でその部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
String

source 内で検索する文字列。

options
CompareOptions

sourcevalue の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Int32

指定した比較オプションを使用して、source 内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。

例外

sourcenullです。

または

valuenullです。

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 値は無効です。

値がOrdinal含まれていない場合options、このオーバーロードはカルチャに依存する検索を実行します。 合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値は、カルチャによっては、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。 値がOrdinal含まれている場合options、このオーバーロードは序数 (カルチャを区別しない) 検索を実行します。ここで、Unicode 値が比較されます。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索の場合 (つまり、optionsOrdinal または OrdinalIgnoreCase でない場合)、value に無視できる文字が含まれていると、その文字を削除して検索した場合と同じ結果になります。 1 つ以上の無視可能な文字のみで構成されている場合value、メソッドは常に LastIndexOf(String, String, CompareOptions) .sourceLength - 1 で最後のインデックス位置 sourceを表します。 次の例では、このメソッドを使用して、 LastIndexOf(String, String, CompareOptions) 2 つの文字列で 3 つの部分文字列 (ソフト ハイフン (U+00AD)、ソフト ハイフンの後に "n"、ソフト ハイフンの後に "m") を検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 ソフト ハイフンは無視できる文字であるため、カルチャに依存する検索では、検索文字列にソフト ハイフンが含まれていない場合に返されるのと同じ値が返されます。 ただし、序数検索では、1 つの文字列でソフト ハイフンが正常に検出され、2 番目の文字列に含まれていないことが報告されます。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable5.cs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable5.vb" id="Snippet6":::

こちらもご覧ください

適用対象

LastIndexOf(String, Char, Int32)

指定した文字を検索し、検索対象文字列の先頭から指定したインデックスまでの範囲内で、その文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
Char

source 内で検索する文字。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

戻り値

Int32

source の先頭から startIndex までの source の範囲内で、value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

startIndexsource の有効なインデックスの範囲外です。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。 IndexOf LastIndexOf同じstartIndexパラメーターであっても、文字列のさまざまな部分で検索されていることに注意してください。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、文字列の先頭から始まり startIndex 、末尾から後方に検索されます。

このオーバーロードは、カルチャに依存する検索を実行します。 文字が、合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値の場合、カルチャによっては、正しいシーケンス ("AE" (U+0041、U+0045) など) でコンポーネントが発生した場合と同等と見なされる場合があります。 Unicode 値が同じ場合にのみ文字が別の文字と等価と見なされる序数 (カルチャに依存しない) 検索を実行するには、型 CompareOptions のパラメーターを持つオーバーロードのいずれかを呼び出し、値を使用する Ordinal 必要があります。 文字の検索の String.LastIndexOf オーバーロードは序数検索を実行しますが、文字列を検索する場合はカルチャに依存する検索を実行します。

注意

可能であれば、予期される比較の種類を指定する型 CompareOptions のパラメーターを持つ文字列比較メソッドを呼び出す必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索では、無視できる文字の場合 value 、結果はその文字を削除した検索と同じです。 この場合、メソッドは LastIndexOf(String, Char, Int32) 常に、検索の開始位置である文字位置を返 startIndexします。 次の例では、このメソッドを使用して、 LastIndexOf(String, Char, Int32) 最後の "m" の前にあるソフト ハイフン (U+00AD) を 2 つの文字列で検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 どちらの場合も、ソフト ハイフンは無視できる文字であるため、このメソッドは "m" のインデックス位置を返します。これは 、 の値 startIndexです。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable4.cs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable4.vb" id="Snippet5":::

こちらもご覧ください

適用対象

LastIndexOf(String, Char, CompareOptions)

指定した CompareOptions 値を使用して、指定した文字を検索し、検索対象文字列全体内でその文字が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
Char

source 内で検索する文字。

options
CompareOptions

sourcevalue の比較方法を定義する値。 options は、列挙値 Ordinal であるか、または IgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType の 1 つ以上の値のビットごとの組み合わせです。

戻り値

Int32

指定した比較オプションを使用して、source 内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。

例外

sourcenullです。

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 値は無効です。

値がOrdinal含まれていない場合options、このオーバーロードはカルチャに依存する検索を実行します。 文字が、合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値の場合、カルチャによっては、正しいシーケンス ("AE" (U+0041、U+0045) など) でコンポーネントが発生した場合と同等と見なされる場合があります。 値がOrdinal含まれている場合options、このオーバーロードは序数 (カルチャに依存しない) 検索を実行します。 文字は、Unicode 値が同じ場合にのみ、別の文字と同等と見なされます。 文字の検索の String.LastIndexOf オーバーロードは序数検索を実行しますが、文字列を検索する場合はカルチャに依存する検索を実行します。

注意

可能であれば、予期される比較の種類を指定する型 CompareOptions のパラメーターを持つ文字列比較メソッドを呼び出す必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存する検索では、無視できる文字の場合 value 、結果はその文字を削除した検索と同じです。 この場合、メソッドは LastIndexOf(String, Char, CompareOptions) 常に最後の文字位置を source 返して、最後に一致が見つかった sourceことを示します。 次の例では、このメソッドを LastIndexOf(String, Char, CompareOptions) 使用して、2 つの文字列でソフト ハイフン (U+00AD) を検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 どちらの場合も、ソフト ハイフンは無視できる文字であるため、カルチャに依存する検索では、ソース文字列内の最後のインデックス位置が返されます。 これに対し、序数検索では、1 つの文字列でソフト ハイフンが正常に検出され、2 番目の文字列に存在しないという報告が行われます。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable3.cs" id="Snippet4":::::code language="vb" source=":code language="vb" source="~/snippets/visualbasic/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

source 内で検索する Rune

options
CompareOptions

検索中に使用する CompareOptions 列挙値の任意の組み合わせ。 既定値は None です。

戻り値

Int32

value が最後に現れる source のゼロから始まるインデックス番号。あるいは、source 内で value が見つからない場合は負の値。

例外

options には、サポートされていない組み合わせのフラグが含まれています。

適用対象

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

指定の読み取り専用文字スパン内で最後に現れる部分文字列を検索します。

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

パラメーター

source
ReadOnlySpan<Char>

中で検索する読み取り専用文字スパン。

value
ReadOnlySpan<Char>

source の中で検索する部分文字列。

options
CompareOptions

検索中に使用する CompareOptions 列挙値の任意の組み合わせ。 既定値は None です。

戻り値

Int32

部分文字列 value が最後に現れる source のゼロから始まるインデックス番号。あるいは、source 内で value が見つからない場合は負の値。

例外

options には、サポートされていない組み合わせのフラグが含まれています。

適用対象

LastIndexOf(String, String)

指定した部分文字列を検索し、検索対象文字列全体内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
String

source 内で検索する文字列。

戻り値

Int32

source 内で value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。

例外

sourcenullです。

または

valuenullです。

次の例では、文字列内の文字または部分文字列の最初と最後の出現のインデックスを決定します。

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) などの事前計算済み文字を表す Unicode 値は、カルチャによっては、"AE" (U+0041、U+0045) などの正しいシーケンスで文字のコンポーネントが発生した場合と同等と見なされる場合があります。 Unicode 値を比較する序数 (カルチャに依存しない) 検索を実行するには、型 CompareOptions のパラメーターを持つオーバーロードのいずれかを呼び出し、値を使用する CompareOptions.Ordinal 必要があります。

注意

可能であれば、予期される比較の種類を指定する型 CompareOptions のパラメーターを持つ文字列比較メソッドを呼び出す必要があります。 一般的なルールとして、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり、セキュリティを比較したり CompareOptions.OrdinalIgnoreCase するには、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存した検索では、value に無視できる文字が含まれている場合、その文字を削除して検索した場合と同じ結果になります。 1 つ以上の無視可能な文字のみで構成されている場合 value 、メソッドは常に LastIndexOf(String, String) 返します sourceLength - 1。これは、次の最後のインデックス位置を source表します。 次の例では、このメソッドを使用して、 LastIndexOf(String, String) 3 つの部分文字列 (ソフト ハイフン (U+00AD)、ソフト ハイフンの後に "n"、ソフト ハイフンの後に "m") を 2 つの文字列で検索します。 文字列の 1 つのみにソフト ハイフンが含まれます。 いずれの場合も、ソフト ハイフンは無視できる文字であるため、結果はソフト ハイフンが含 valueまれていない場合と同じです。 ソフト ハイフンのみを検索すると、メソッドは 6 と 5 を返します。 これらの値は、2 つの文字列の最後の文字のインデックスに対応します。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable1.cs" id="Snippet2":::::code language="vb" source="::::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable1.vb" id="Snippet2::

こちらもご覧ください

適用対象

LastIndexOf(String, String, Int32)

指定した部分文字列を検索し、検索対象文字列の先頭から指定したインデックスまでの範囲内で、その部分文字列が最後に出現する位置の 0 から始まるインデックス番号を返します。

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

パラメーター

source
String

検索対象の文字列。

value
String

source 内で検索する文字列。

startIndex
Int32

後方検索の開始位置を示す 0 から始まるインデックス。

戻り値

Int32

source の先頭から startIndex までの source の範囲内で、value が見つかった場合は、最後に見つかった位置の 0 から始まるインデックス番号、それ以外の場合は -1 です。 value が無視できる文字の場合は startIndex を返します。

例外

sourcenullです。

または

valuenullです。

startIndexsource の有効なインデックスの範囲外です。

次の例では、文字列の一部内の文字または部分文字列の最初と最後の出現のインデックスを決定します。 IndexOf LastIndexOf同じstartIndexパラメーターを使用しても、文字列のさまざまな部分で検索されていることに注意してください。

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

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

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

/*
This code produces the following output.

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

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

*/
using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

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

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

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

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

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

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

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

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

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

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

      if ( mySize > -1 )  {

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

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

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


/*
This code produces the following output.

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

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

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

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

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

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

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

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

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

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

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

   End Sub

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

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

      If mySize > - 1 Then

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

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

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

      End If 

   End Sub

End Class


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

注釈

ソース文字列は、文字列の startIndex 先頭から始まり、先頭から後方に検索されます。

このオーバーロードは、カルチャに依存する検索を実行します。 合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode 値は、カルチャによっては、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。 Unicode 値が比較される序数 (カルチャに依存しない) 検索を実行するには、型 CompareOptions のパラメーターを持つオーバーロードのいずれかを呼び出し、値を使用する CompareOptions.Ordinal 必要があります。

注意

可能であれば、型のパラメーター CompareOptions を持つ文字列比較メソッドを呼び出して、予想される比較の種類を指定する必要があります。 原則として、ユーザー インターフェイスに表示される文字列を比較したり、セキュリティ比較を指定 CompareOptions.Ordinal したり CompareOptions.OrdinalIgnoreCase するために、言語オプション (現在のカルチャを使用) を使用します。

注意 (呼び出し元)

文字セットには無視できる文字が含まれます。これは、言語的またはカルチャに依存する並べ替えを実行するときに考慮されない文字です。 カルチャに依存した検索では、value に無視できる文字が含まれている場合、その文字を削除して検索した場合と同じ結果になります。 1 つ以上の無視可能な文字のみで構成されている場合 valueLastIndexOf(String, String, Int32) メソッドは常に検索の開始位置である文字位置を返 startIndexします。 次の例では、このメソッドを使用して、 LastIndexOf(String, String, Int32) ソフト ハイフン (U+00AD) を含み、文字列内の最後の "m" の前または末尾に含まれる部分文字列を検索します。 検索文字列のソフト ハイフンは無視されるため、メソッドを呼び出してソフト ハイフンで構成される部分文字列を検索し、"m" は文字列内の "m" の位置を返します。一方、それを呼び出してソフト ハイフンで構成される部分文字列を検索し、"n" は "n" の位置を返します。 検索文字列にソフト ハイフンのみが含まれている場合、メソッドは値を表す "m" のインデックスを startIndex返します。

::code language="csharp" source="~/snippets/csharp/System.Globalization/CompareInfo/LastIndexOf/lastignorable6.cs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.globalization.compareinfo.lastindexof/vb/lastignorable6.vb" id="Snippet7":::

こちらもご覧ください

適用対象