次の方法で共有


CompareInfo.LastIndexOf メソッド

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

オーバーロードの一覧

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, Char) As Integer

[C#] public virtual int LastIndexOf(string, char);

[C++] public: virtual int LastIndexOf(String*, __wchar_t);

[JScript] public function LastIndexOf(String, Char) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, String) As Integer

[C#] public virtual int LastIndexOf(string, string);

[C++] public: virtual int LastIndexOf(String*, String*);

[JScript] public function LastIndexOf(String, String) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, Char, CompareOptions) As Integer

[C#] public virtual int LastIndexOf(string, char, CompareOptions);

[C++] public: virtual int LastIndexOf(String*, __wchar_t, CompareOptions);

[JScript] public function LastIndexOf(String, Char, CompareOptions) : int;

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

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, Char, Integer) As Integer

[C#] public virtual int LastIndexOf(string, char, int);

[C++] public: virtual int LastIndexOf(String*, __wchar_t, int);

[JScript] public function LastIndexOf(String, Char, int) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, String, CompareOptions) As Integer

[C#] public virtual int LastIndexOf(string, string, CompareOptions);

[C++] public: virtual int LastIndexOf(String*, String*, CompareOptions);

[JScript] public function LastIndexOf(String, String, CompareOptions) : int;

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

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, String, Integer) As Integer

[C#] public virtual int LastIndexOf(string, string, int);

[C++] public: virtual int LastIndexOf(String*, String*, int);

[JScript] public function LastIndexOf(String, String, int) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, Char, Integer, CompareOptions) As Integer

[C#] public virtual int LastIndexOf(string, char, int, CompareOptions);

[C++] public: virtual int LastIndexOf(String*, __wchar_t, int, CompareOptions);

[JScript] public function LastIndexOf(String, Char, int, CompareOptions) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, Char, Integer, Integer) As Integer

[C#] public virtual int LastIndexOf(string, char, int, int);

[C++] public: virtual int LastIndexOf(String*, __wchar_t, int, int);

[JScript] public function LastIndexOf(String, Char, int, int) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, String, Integer, CompareOptions) As Integer

[C#] public virtual int LastIndexOf(string, string, int, CompareOptions);

[C++] public: virtual int LastIndexOf(String*, String*, int, CompareOptions);

[JScript] public function LastIndexOf(String, String, int, CompareOptions) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, String, Integer, Integer) As Integer

[C#] public virtual int LastIndexOf(string, string, int, int);

[C++] public: virtual int LastIndexOf(String*, String*, int, int);

[JScript] public function LastIndexOf(String, String, int, int) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, Char, Integer, Integer, CompareOptions) As Integer

[C#] public virtual int LastIndexOf(string, char, int, int, CompareOptions);

[C++] public: virtual int LastIndexOf(String*, __wchar_t, int, int, CompareOptions);

[JScript] public function LastIndexOf(String, Char, int, int, CompareOptions) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function LastIndexOf(String, String, Integer, Integer, CompareOptions) As Integer

[C#] public virtual int LastIndexOf(string, string, int, int, CompareOptions);

[C++] public: virtual int LastIndexOf(String*, String*, int, int, CompareOptions);

[JScript] public function LastIndexOf(String, String, int, int, CompareOptions) : int;

使用例

[Visual Basic, C#, C++] 次に示すのは、文字列の一部分の、最初と最後に出現する文字または部分文字列のインデックスを調べるコード例です。

[Visual Basic, C#, C++] メモ   ここでは、LastIndexOf のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

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 'Main

   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 'PrintMarker

End Class 'SamplesCompareInfo 


'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


[C#] 
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

*/

[C++] 
#using <mscorlib.dll>
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.
      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( S"{0}{1}", Prefix, new 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 = new String( '-', iS );
   String* myT2;

   // Searches for the ligature ニ.
   String* myStr = S"Is AE or ae the same as ニ or ・";
   myT2 = new String( '-', myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( S"Original      : {0}", myStr );
   Console::WriteLine( S"No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( S"           AE : ", myComp->IndexOf( myStr, S"AE", iS, iL ), myComp->LastIndexOf( myStr, S"AE", iS + iL - 1, iL ) );
   PrintMarker( S"           ae : ", myComp->IndexOf( myStr, S"ae", iS, iL ), myComp->LastIndexOf( myStr, S"ae", iS + iL - 1, iL ) );
   PrintMarker( S"            ニ : ", myComp->IndexOf( myStr, L'ニ', iS, iL ), myComp->LastIndexOf( myStr, L'ニ', iS + iL - 1, iL ) );
   PrintMarker( S"            ・: ", myComp->IndexOf( myStr, L'・, iS, iL ), myComp->LastIndexOf( myStr, L'・, iS + iL - 1, iL ) );
   Console::WriteLine( S"Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( S"           AE : ", myComp->IndexOf( myStr, S"AE", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, S"AE", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( S"           ae : ", myComp->IndexOf( myStr, S"ae", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, S"ae", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( S"            ニ : ", myComp->IndexOf( myStr, L'ニ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ニ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( S"            ・: ", myComp->IndexOf( myStr, L'・, iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'・, iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( S"IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( S"           AE : ", myComp->IndexOf( myStr, S"AE", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, S"AE", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( S"           ae : ", myComp->IndexOf( myStr, S"ae", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, S"ae", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( S"            ニ : ", myComp->IndexOf( myStr, L'ニ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ニ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( S"            ・: ", 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 = S"Is U\u0308 or u\u0308 the same as \u00DC or \u00FC?";
   myT2 = new String( '-', myStr->Length - iS - iL );
   Console::WriteLine();
   Console::WriteLine( S"Original      : {0}", myStr );
   Console::WriteLine( S"No options    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( S"           U\u0308 : ", myComp->IndexOf( myStr, S"U\u0308", iS, iL ), myComp->LastIndexOf( myStr, S"U\u0308", iS + iL - 1, iL ) );
   PrintMarker( S"           u\u0308 : ", myComp->IndexOf( myStr, S"u\u0308", iS, iL ), myComp->LastIndexOf( myStr, S"u\u0308", iS + iL - 1, iL ) );
   PrintMarker( S"            ワ : ", myComp->IndexOf( myStr, L'ワ', iS, iL ), myComp->LastIndexOf( myStr, L'ワ', iS + iL - 1, iL ) );
   PrintMarker( S"            ・: ", myComp->IndexOf( myStr, L'・, iS, iL ), myComp->LastIndexOf( myStr, L'・, iS + iL - 1, iL ) );
   Console::WriteLine( S"Ordinal       : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( S"           U\u0308 : ", myComp->IndexOf( myStr, S"U\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, S"U\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( S"           u\u0308 : ", myComp->IndexOf( myStr, S"u\u0308", iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, S"u\u0308", iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( S"            ワ : ", myComp->IndexOf( myStr, L'ワ', iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'ワ', iS + iL - 1, iL, CompareOptions::Ordinal ) );
   PrintMarker( S"            ・: ", myComp->IndexOf( myStr, L'・, iS, iL, CompareOptions::Ordinal ), myComp->LastIndexOf( myStr, L'・, iS + iL - 1, iL, CompareOptions::Ordinal ) );
   Console::WriteLine( S"IgnoreCase    : {0}{1}{2}", myT1, myStr->Substring( iS, iL ), myT2 );
   PrintMarker( S"           U\u0308 : ", myComp->IndexOf( myStr, S"U\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, S"U\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( S"           u\u0308 : ", myComp->IndexOf( myStr, S"u\u0308", iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, S"u\u0308", iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( S"            ワ : ", myComp->IndexOf( myStr, L'ワ', iS, iL, CompareOptions::IgnoreCase ), myComp->LastIndexOf( myStr, L'ワ', iS + iL - 1, iL, CompareOptions::IgnoreCase ) );
   PrintMarker( S"            ・: ", 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

*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

CompareInfo クラス | CompareInfo メンバ | System.Globalization 名前空間