String.LastIndexOfAny 메서드

정의

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 0부터 시작하는 인덱스 위치를 보고합니다. 이 인스턴스에 해당 문자가 없으면 메서드는 -1을 반환합니다.

오버로드

LastIndexOfAny(Char[])

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 0부터 시작하는 인덱스 위치를 보고합니다.

LastIndexOfAny(Char[], Int32)

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 0부터 시작하는 인덱스 위치를 보고합니다. 지정된 문자 위치에서 시작하고 문자열의 시작 부분을 향해 뒤로 검색이 진행됩니다.

LastIndexOfAny(Char[], Int32, Int32)

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 0부터 시작하는 인덱스 위치를 보고합니다. 지정된 문자 위치에서 검색을 시작하여 지정된 수의 문자 위치에 대한 문자열의 시작 부분 쪽으로 뒤로 검색합니다.

LastIndexOfAny(Char[])

Source:
String.Searching.cs
Source:
String.Searching.cs
Source:
String.Searching.cs

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 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[]

검색할 문자를 하나 이상 포함하는 유니코드 문자 배열입니다.

반환

이 인스턴스에서 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부터 시작합니다.

이 메서드는 이 instance 마지막 문자 위치에서 검색을 시작하고 의 문자를 찾거나 첫 번째 문자 anyOf 위치를 검사할 때까지 시작 부분으로 뒤로 진행합니다. 검색은 대/소문자를 구분합니다.

이 메서드는 서수(문화권을 구분하지 않는) 검색을 수행합니다. 여기서 문자는 유니코드 스칼라 값이 동일한 경우에만 다른 문자와 동일한 것으로 간주됩니다. 문화권에 민감한 검색을 수행하려면 메서드를 사용합니다 CompareInfo.LastIndexOf . 여기서 합자 "Æ"(U+00C6)와 같이 미리 구성된 문자를 나타내는 유니코드 스칼라 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다.

추가 정보

적용 대상

LastIndexOfAny(Char[], Int32)

Source:
String.Searching.cs
Source:
String.Searching.cs
Source:
String.Searching.cs

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 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[]

검색할 문자를 하나 이상 포함하는 유니코드 문자 배열입니다.

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부터 시작합니다.

이 메서드는 이 instance 문자 위치에서 검색 startIndex 을 시작하고 의 문자를 찾거나 첫 번째 문자 anyOf 위치를 검사할 때까지 시작 부분으로 뒤로 진행합니다. 검색은 대/소문자를 구분합니다.

이 메서드는 서수(문화권을 구분하지 않는) 검색을 수행합니다. 여기서 문자는 유니코드 스칼라 값이 동일한 경우에만 다른 문자와 동일한 것으로 간주됩니다. 문화권에 민감한 검색을 수행하려면 메서드를 사용합니다 CompareInfo.LastIndexOf . 여기서 합자 "Æ"(U+00C6)와 같이 미리 구성된 문자를 나타내는 유니코드 스칼라 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다.

추가 정보

적용 대상

LastIndexOfAny(Char[], Int32, Int32)

Source:
String.Searching.cs
Source:
String.Searching.cs
Source:
String.Searching.cs

유니코드 배열에서 지정된 하나 이상의 문자 중에 이 인스턴스에서 마지막으로 발견되는 문자의 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[]

검색할 문자를 하나 이상 포함하는 유니코드 문자 배열입니다.

startIndex
Int32

검색을 시작할 위치입니다. startIndex에서 이 인스턴스의 시작 부분을 향해 검색이 진행됩니다.

count
Int32

검사할 문자 위치의 수입니다.

반환

이 인스턴스에서 anyOf의 문자가 마지막으로 발견된 인덱스 위치입니다. anyOf의 문자가 발견되지 않거나 현재 인스턴스가 Empty와 동일하면 -1입니다.

예외

anyOfnull입니다.

현재 인스턴스가 Empty 같지 않고 count 또는 startIndex가 음수입니다.

또는

현재 인스턴스가 Empty와 같지 않고 startIndex - count + 1이 음수입니다.

예제

다음 예제에서는 다른 문자열의 부분 문자열 내에서 문자열 "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부터 시작합니다.

이 메서드는 이 instance 문자 위치에서 검색 startIndex 을 시작하고 의 문자를 찾거나 count 문자 anyOf 위치를 검사할 때까지 시작 부분으로 뒤로 진행합니다. 검색은 대/소문자를 구분합니다.

이 메서드는 서수(문화권을 구분하지 않는) 검색을 수행합니다. 여기서 문자는 유니코드 스칼라 값이 동일한 경우에만 다른 문자와 동일한 것으로 간주됩니다. 문화권에 민감한 검색을 수행하려면 메서드를 사용합니다 CompareInfo.LastIndexOf . 여기서 합자 "Æ"(U+00C6)와 같이 미리 구성된 문자를 나타내는 유니코드 스칼라 값은 문화권에 따라 "AE"(U+0041, U+0045)와 같은 올바른 시퀀스에서 문자의 구성 요소가 발생하는 것과 동일한 것으로 간주될 수 있습니다.

추가 정보

적용 대상