String.LastIndexOfAny メソッド

定義

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。 このインスタンス内で配列内の文字が見つからない場合、このメソッドは -1 を返します。

オーバーロード

LastIndexOfAny(Char[])

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。

LastIndexOfAny(Char[], Int32)

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。 検索は、指定された文字位置から開始され、文字列の先頭に向かって逆方向に進みます。

LastIndexOfAny(Char[], Int32, Int32)

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。 検索は指定された文字位置から開始し、文字列の開始に向かって後方に移動し、文字位置の指定された数だけ行われます。

LastIndexOfAny(Char[])

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。

public:
 int LastIndexOfAny(cli::array <char> ^ anyOf);
public int LastIndexOfAny (char[] anyOf);
member this.LastIndexOfAny : char[] -> int
Public Function LastIndexOfAny (anyOf As Char()) As Integer

パラメーター

anyOf
Char[]

シークする 1 つ以上の文字を格納している、Unicode 文字の配列。

戻り値

anyOf 内の文字がこのインスタンスで最後に見つかった場所のインデックス位置。anyOf 内の文字が見つからなかった場合は -1。

例外

anyOfnullです。

次の例では、文字列 "is" 内の任意の文字が別の文字列内で最後に出現したインデックスを検索します。

// Sample for String::LastIndexOfAny(Char[])
using namespace System;
int main()
{
   String^ br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
   String^ br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
   String^ str = "Now is the time for all good men to come to the aid of their party.";
   int start;
   int at;
   String^ target = "is";
   array<Char>^anyOf = target->ToCharArray();
   start = str->Length - 1;
   Console::WriteLine( "The last character occurrence  from position {0} to 0.", start );
   Console::WriteLine( "{1}{0}{2}{0}{3}{0}", Environment::NewLine, br1, br2, str );
   Console::Write( "A character in '{0}' occurs at position: ", target );
   at = str->LastIndexOfAny( anyOf );
   if ( at > -1 )
      Console::Write( at );
   else
      Console::Write( "(not found)" );

   Console::Write( "{0}{0}{0}", Environment::NewLine );
}

/*
This example produces the following results:
The last character occurrence  from position 66 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 58


*/
// Sample for String.LastIndexOfAny(Char[])
using System;

class Sample {
    public static void Main() {

    string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
    string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
    string str = "Now is the time for all good men to come to the aid of their party.";
    int start;
    int at;
    string target = "is";
    char[] anyOf = target.ToCharArray();

    start = str.Length-1;
    Console.WriteLine("The last character occurrence  from position {0} to 0.", start);
    Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
    Console.Write("A character in '{0}' occurs at position: ", target);

    at = str.LastIndexOfAny(anyOf);
    if (at > -1)
        Console.Write(at);
    else
        Console.Write("(not found)");
    Console.Write("{0}{0}{0}", Environment.NewLine);
    }
}
/*
This example produces the following results:
The last character occurrence  from position 66 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 58


*/
// Sample for String.LastIndexOfAny(Char[])
open System

let br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
let br2 = "0123456789012345678901234567890123456789012345678901234567890123456"
let str = "Now is the time for all good men to come to the aid of their party."
let target = "is"
let anyOf = target.ToCharArray()

let start = str.Length - 1
printfn $"The last character occurrence  from position {start} to 0."
printfn $"{br1}{Environment.NewLine}{br2}{Environment.NewLine}{str}{Environment.NewLine}"
printf $"A character in '{target}' occurs at position: "

let at = str.LastIndexOfAny anyOf
if at > -1 then
    printf $"{at}"
else
    printf "(not found)"
printf $"{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}"
(*
This example produces the following results:
The last character occurrence  from position 66 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 58


*)
' Sample for String.LastIndexOfAny(Char[])
 _

Class Sample
   
   Public Shared Sub Main()
      
      Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
      Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
      Dim str As String = "Now is the time for all good men to come to the aid of their party."
      Dim start As Integer
      Dim at As Integer
      Dim target As String = "is"
      Dim anyOf As Char() = target.ToCharArray()
      
      start = str.Length - 1
      Console.WriteLine("The last character occurrence  from position {0} to 0.", start)
      Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str)
      Console.Write("A character in '{0}' occurs at position: ", target)
      
      at = str.LastIndexOfAny(anyOf)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.Write("{0}{0}{0}", Environment.NewLine)
   End Sub
End Class
'
'This example produces the following results:
'The last character occurrence  from position 66 to 0.
'0----+----1----+----2----+----3----+----4----+----5----+----6----+-
'0123456789012345678901234567890123456789012345678901234567890123456
'Now is the time for all good men to come to the aid of their party.
'
'A character in 'is' occurs at position: 58
'
'
'

注釈

インデックス番号は 0 から始まります。

このメソッドは、このインスタンスの最後の文字位置から検索を開始し、 内の文字が見つかるか、最初の文字 anyOf 位置が検査されるまで先頭に向かって後方に進みます。 検索では大文字と小文字が区別されます。

このメソッドは序数 (カルチャを区別しない) 検索を実行します。ここで、文字は Unicode スカラー値が同じ場合にのみ、別の文字と同等と見なされます。 カルチャに依存する検索を実行するには、 メソッドを使用します CompareInfo.LastIndexOf 。ここで、合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode スカラー値は、カルチャに応じて 、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。

こちらもご覧ください

適用対象

LastIndexOfAny(Char[], Int32)

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。 検索は、指定された文字位置から開始され、文字列の先頭に向かって逆方向に進みます。

public:
 int LastIndexOfAny(cli::array <char> ^ anyOf, int startIndex);
public int LastIndexOfAny (char[] anyOf, int startIndex);
member this.LastIndexOfAny : char[] * int -> int
Public Function LastIndexOfAny (anyOf As Char(), startIndex As Integer) As Integer

パラメーター

anyOf
Char[]

シークする 1 つ以上の文字を格納している、Unicode 文字の配列。

startIndex
Int32

検索が開始される位置。 検索は、このインスタンスの先頭に向かって startIndex から開始されます。

戻り値

anyOf 内の文字がこのインスタンスで最後に見つかった場所のインデックス位置。anyOf 内の文字が見つからなかった場合、または現在のインスタンスが Empty と等しい場合は -1。

例外

anyOfnullです。

現在のインスタンスが Empty と等しくなく、startIndex がこのインスタンス内にはない位置を指定しています。

次の例では、文字列 "is" 内の任意の文字が別の文字列の部分文字列内で最後に出現したインデックスを検索します。

// Sample for String::LastIndexOfAny(Char, Int32)
using namespace System;
int main()
{
   String^ br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
   String^ br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
   String^ str = "Now is the time for all good men to come to the aid of their party.";
   int start;
   int at;
   String^ target = "is";
   array<Char>^anyOf = target->ToCharArray();
   start = (str->Length - 1) / 2;
   Console::WriteLine( "The last character occurrence  from position {0} to 0.", start );
   Console::WriteLine( "{1}{0}{2}{0}{3}{0}", Environment::NewLine, br1, br2, str );
   Console::Write( "A character in '{0}' occurs at position: ", target );
   at = str->LastIndexOfAny( anyOf, start );
   if ( at > -1 )
      Console::Write( at );
   else
      Console::Write( "(not found)" );

   Console::Write( "{0}{0}{0}", Environment::NewLine );
}

/*
This example produces the following results:
The last character occurrence  from position 33 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 12


*/
// Sample for String.LastIndexOfAny(Char[], Int32)
using System;

class Sample {
    public static void Main() {

    string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
    string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
    string str = "Now is the time for all good men to come to the aid of their party.";
    int start;
    int at;
    string target = "is";
    char[] anyOf = target.ToCharArray();

    start = (str.Length-1)/2;
    Console.WriteLine("The last character occurrence  from position {0} to 0.", start);
    Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
    Console.Write("A character in '{0}' occurs at position: ", target);

    at = str.LastIndexOfAny(anyOf, start);
    if (at > -1)
        Console.Write(at);
    else
        Console.Write("(not found)");
    Console.Write("{0}{0}{0}", Environment.NewLine);
    }
}
/*
This example produces the following results:
The last character occurrence  from position 33 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 12


*/
// Sample for String.LastIndexOfAny(Char[], Int32)
open System

let br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
let br2 = "0123456789012345678901234567890123456789012345678901234567890123456"
let str = "Now is the time for all good men to come to the aid of their party."
let target = "is"
let anyOf = target.ToCharArray()

let start = (str.Length - 1) / 2
printfn $"The last character occurrence  from position {start} to 0."
printfn $"{br1}{Environment.NewLine}{br2}{Environment.NewLine}{str}{Environment.NewLine}"
printf $"A character in '{target}' occurs at position: "

let at = str.LastIndexOfAny(anyOf, start)
if at > -1 then
    printf $"{at}"
else
    printf "(not found)"
printf $"{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}"
(*
This example produces the following results:
The last character occurrence  from position 33 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'is' occurs at position: 12


*)
' Sample for String.LastIndexOfAny(Char[], Int32)
 _

Class Sample
   
   Public Shared Sub Main()
      
      Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
      Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
      Dim str As String = "Now is the time for all good men to come to the aid of their party."
      Dim start As Integer
      Dim at As Integer
      Dim target As String = "is"
      Dim anyOf As Char() = target.ToCharArray()
      
      start =(str.Length - 1) / 2
      Console.WriteLine("The last character occurrence  from position {0} to 0.", start)
      Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str)
      Console.Write("A character in '{0}' occurs at position: ", target)
      
      at = str.LastIndexOfAny(anyOf, start)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.Write("{0}{0}{0}", Environment.NewLine)
   End Sub
End Class
'
'This example produces the following results:
'The last character occurrence  from position 33 to 0.
'0----+----1----+----2----+----3----+----4----+----5----+----6----+-
'0123456789012345678901234567890123456789012345678901234567890123456
'Now is the time for all good men to come to the aid of their party.
'
'A character in 'is' occurs at position: 12
'
'
'

注釈

インデックス番号は 0 から始まります。

このメソッドは、このインスタンスの文字位置から検索を startIndex 開始し、 内の文字が見つかるか、最初の文字 anyOf 位置が検査されるまで先頭に向かって後方に進みます。 検索では大文字と小文字が区別されます。

このメソッドは序数 (カルチャを区別しない) 検索を実行します。ここで、文字は Unicode スカラー値が同じ場合にのみ、別の文字と同等と見なされます。 カルチャに依存する検索を実行するには、 メソッドを使用します CompareInfo.LastIndexOf 。ここで、合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode スカラー値は、カルチャに応じて 、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。

こちらもご覧ください

適用対象

LastIndexOfAny(Char[], Int32, Int32)

Unicode 配列内の指定した 1 つ以上の文字がこのインスタンスで最後に見つかった 0 から始まるインデックス位置をレポートします。 検索は指定された文字位置から開始し、文字列の開始に向かって後方に移動し、文字位置の指定された数だけ行われます。

public:
 int LastIndexOfAny(cli::array <char> ^ anyOf, int startIndex, int count);
public int LastIndexOfAny (char[] anyOf, int startIndex, int count);
member this.LastIndexOfAny : char[] * int * int -> int
Public Function LastIndexOfAny (anyOf As Char(), startIndex As Integer, count As Integer) As Integer

パラメーター

anyOf
Char[]

シークする 1 つ以上の文字を格納している、Unicode 文字の配列。

startIndex
Int32

検索が開始される位置。 検索は、このインスタンスの先頭に向かって startIndex から開始されます。

count
Int32

検査する文字位置の数。

戻り値

anyOf 内の文字がこのインスタンスで最後に見つかった場所のインデックス位置。anyOf 内の文字が見つからなかった場合、または現在のインスタンスが Empty と等しい場合は -1。

例外

anyOfnullです。

現在のインスタンスが Empty と等しくなく、count または startIndex が負の値です。

または

現在のインスタンスが Empty と等しくなく、startIndex - count + 1 が 0 未満です。

次の例では、文字列 "aid" 内の任意の文字が別の文字列の部分文字列内で最後に出現したインデックスを検索します。

// Sample for String::LastIndexOfAny(Char[], Int32, Int32)
using namespace System;
int main()
{
   String^ br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
   String^ br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
   String^ str = "Now is the time for all good men to come to the aid of their party.";
   int start;
   int at;
   int count;
   String^ target = "aid";
   array<Char>^anyOf = target->ToCharArray();
   start = ((str->Length - 1) * 2) / 3;
   count = (str->Length - 1) / 3;
   Console::WriteLine( "The last character occurrence from position {0} for {1} characters.", start, count );
   Console::WriteLine( "{1}{0}{2}{0}{3}{0}", Environment::NewLine, br1, br2, str );
   Console::Write( "A character in '{0}' occurs at position: ", target );
   at = str->LastIndexOfAny( anyOf, start, count );
   if ( at > -1 )
      Console::Write( at );
   else
      Console::Write( "(not found)" );

   Console::Write( "{0}{0}{0}", Environment::NewLine );
}

/*
This example produces the following results:
The last character occurrence from position 44 for 22 characters.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'aid' occurs at position: 27
*/
// Sample for String.LastIndexOfAny(Char[], Int32, Int32)
using System;

class Sample {
    public static void Main() {

    string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
    string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
    string str = "Now is the time for all good men to come to the aid of their party.";
    int start;
    int at;
    int count;
    string target = "aid";
    char[] anyOf = target.ToCharArray();

    start = ((str.Length-1)*2)/3;
    count = (str.Length-1)/3;
    Console.WriteLine("The last character occurrence from position {0} for {1} characters.", start, count);
    Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
    Console.Write("A character in '{0}' occurs at position: ", target);

    at = str.LastIndexOfAny(anyOf, start, count);
    if (at > -1)
        Console.Write(at);
    else
        Console.Write("(not found)");
    Console.Write("{0}{0}{0}", Environment.NewLine);
    }
}
/*
This example produces the following results:
The last character occurrence from position 44 for 22 characters.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'aid' occurs at position: 27
*/
// Sample for String.LastIndexOfAny(Char[], Int32, Int32)
open System

let br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
let br2 = "0123456789012345678901234567890123456789012345678901234567890123456"
let str = "Now is the time for all good men to come to the aid of their party."
let target = "aid"
let anyOf = target.ToCharArray()

let start = ((str.Length - 1) * 2) / 3
let count = (str.Length - 1) / 3
printfn $"The last character occurrence from position {start} for {count} characters."
printfn $"{br1}{Environment.NewLine}{br2}{Environment.NewLine}{str}{Environment.NewLine}"
printf $"A character in '{target}' occurs at position: "

let at = str.LastIndexOfAny(anyOf, start, count)
if at > -1 then
    printf $"{at}"
else
    printf "(not found)"
printf $"{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}"
(*
This example produces the following results:
The last character occurrence from position 44 for 22 characters.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

A character in 'aid' occurs at position: 27
*)
' Sample for String.LastIndexOfAny(Char[], Int32, Int32)
 _

Class Sample
   
   Public Shared Sub Main()
      
      Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
      Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
      Dim str As String = "Now is the time for all good men to come to the aid of their party."
      Dim start As Integer
      Dim at As Integer
      Dim count As Integer
      Dim target As String = "aid"
      Dim anyOf As Char() = target.ToCharArray()
      
      start =(str.Length - 1) * 2 / 3
      count =(str.Length - 1) / 3
      Console.WriteLine("The last character occurrence from position {0} for {1} characters.", start, count)
      Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str)
      Console.Write("A character in '{0}' occurs at position: ", target)
      
      at = str.LastIndexOfAny(anyOf, start, count)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.Write("{0}{0}{0}", Environment.NewLine)
   End Sub
End Class
'
'This example produces the following results:
'The last character occurrence from position 44 for 22 characters.
'0----+----1----+----2----+----3----+----4----+----5----+----6----+-
'0123456789012345678901234567890123456789012345678901234567890123456
'Now is the time for all good men to come to the aid of their party.
'
'A character in 'aid' occurs at position: 27
'

注釈

インデックス番号は 0 から始まります。

このメソッドは、このインスタンスの文字位置から検索をstartIndex開始し、 内の文字が見つかるかcount、文字anyOf位置が検査されるまで先頭に向かって後方に進みます。 検索では大文字と小文字が区別されます。

このメソッドは序数 (カルチャを区別しない) 検索を実行します。ここで、文字は Unicode スカラー値が同じ場合にのみ、別の文字と同等と見なされます。 カルチャに依存する検索を実行するには、 メソッドを使用します CompareInfo.LastIndexOf 。ここで、合字 "Æ" (U+00C6) などの事前計算済み文字を表す Unicode スカラー値は、カルチャに応じて 、"AE" (U+0041、U+0045) などの正しいシーケンス内の文字のコンポーネントの出現と同等と見なされる場合があります。

こちらもご覧ください

適用対象