String.IndexOfAny 메서드

정의

지정된 유니코드 문자 배열에 있는 문자 중에서 이 인스턴스에서 맨 처음 발견되는 문자의 인덱스를 보고합니다. 이 인스턴스에 해당 문자가 없으면 메서드는 -1을 반환합니다.

오버로드

IndexOfAny(Char[])

지정된 유니코드 문자 배열에 있는 문자 중에 이 인스턴스에서 맨 처음 발견되는 문자의 0부터 시작하는 인덱스를 보고합니다.

IndexOfAny(Char[], Int32)

지정된 유니코드 문자 배열에 있는 문자 중에 이 인스턴스에서 맨 처음 발견되는 문자의 0부터 시작하는 인덱스를 보고합니다. 검색은 지정된 문자 위치에서 시작됩니다.

IndexOfAny(Char[], Int32, Int32)

지정된 유니코드 문자 배열에 있는 문자 중에 이 인스턴스에서 맨 처음 발견되는 문자의 0부터 시작하는 인덱스를 보고합니다. 검색은 지정된 문자 위치에서 시작하여 지정된 수의 문자 위치를 검사합니다.

IndexOfAny(Char[])

지정된 유니코드 문자 배열에 있는 문자 중에 이 인스턴스에서 맨 처음 발견되는 문자의 0부터 시작하는 인덱스를 보고합니다.

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

매개 변수

anyOf
Char[]

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

반환

이 인스턴스에서 anyOf의 문자가 처음 발견된 인덱스 위치(0부터 시작)입니다. anyOf의 문자가 발견되지 않으면 -1입니다.

예외

anyOf이(가) null인 경우

예제

다음 예제에서는 문자열에서 첫 번째 모음을 찾습니다.

using System;

public class Example
{
   public static void Main()
   {
      char[] chars = { 'a', 'e', 'i', 'o', 'u', 'y', 
                       'A', 'E', 'I', 'O', 'U', 'Y' };
      String s = "The long and winding road...";
      Console.WriteLine("The first vowel in \n   {0}\nis found at position {1}", 
                        s, s.IndexOfAny(chars) + 1);                         
   }
}
// The example displays the following output:
//       The first vowel in
//          The long and winding road...
//       is found at position 3
let chars = [| 'a'; 'e'; 'i'; 'o'; 'u'; 'y'
               'A'; 'E'; 'I'; 'O'; 'U'; 'Y' |]
let s = "The long and winding road..."
printfn $"The first vowel in \n   {s}\nis found at position {s.IndexOfAny chars + 1}"
// The example displays the following output:
//       The first vowel in
//          The long and winding road...
//       is found at position 3
Module Example
   Public Sub Main()
      Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c, 
                              "A"c, "E"c, "I"c, "O"c, "U"c, "Y"c }
      Dim s As String = "The long and winding road..."
      Console.WriteLine("The first vowel in {2}   {0}{2}is found at position {1}", 
                        s, s.IndexOfAny(chars) + 1, vbCrLf)                         
   End Sub
End Module
' The example displays the following output:
'       The first vowel in
'          The long and winding road...
'       is found at position 3

설명

인덱스 번호 매기기 시작은 0부터 시작합니다.

검색 anyOf 은 대/소문자를 구분합니다. 가 빈 배열인 경우 anyOf 메서드는 문자열의 시작 부분에서 일치 항목(즉, 인덱스 0)을 찾습니다.

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

추가 정보

적용 대상

IndexOfAny(Char[], Int32)

지정된 유니코드 문자 배열에 있는 문자 중에 이 인스턴스에서 맨 처음 발견되는 문자의 0부터 시작하는 인덱스를 보고합니다. 검색은 지정된 문자 위치에서 시작됩니다.

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

매개 변수

anyOf
Char[]

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

startIndex
Int32

검색을 시작할 위치입니다.

반환

이 인스턴스에서 anyOf의 문자가 처음 발견된 인덱스 위치(0부터 시작)입니다. anyOf의 문자가 발견되지 않으면 -1입니다.

예외

anyOf이(가) null인 경우

startIndex가 음수입니다.

또는

startIndex가 이 인스턴스의 문자 수보다 큽니다.

예제

다음 예제에서는 다른 문자열의 부분 문자열 내에서 문자열 "is"의 문자 발생 인덱스 를 찾습니다.

// Sample for String::IndexOfAny(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 / 2;
   Console::WriteLine();
   Console::WriteLine( "The first character occurrence from position {0} to {1}.", start, str->Length - 1 );
   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->IndexOfAny( anyOf, start );
   if ( at > -1 )
      Console::Write( at );
   else
      Console::Write( "(not found)" );

   Console::WriteLine();
}

/*

The first character occurrence from position 33 to 66.
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: 49

*/
// Sample for String.IndexOfAny(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/2;
    Console.WriteLine();
    Console.WriteLine("The first character occurrence from position {0} to {1}.",
                           start, str.Length-1);
    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.IndexOfAny(anyOf, start);
    if (at > -1)
        Console.Write(at);
    else
        Console.Write("(not found)");
    Console.WriteLine();
    }
}
/*

The first character occurrence from position 33 to 66.
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: 49

*/
// Sample for String.IndexOfAny(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/2
printfn $"\nThe first character occurrence from position {start} to {str.Length - 1}."
printfn $"{br1}{Environment.NewLine}{br2}{Environment.NewLine}{str}{Environment.NewLine}"
printf $"A character in '{target}' occurs at position: "

let at = str.IndexOfAny(anyOf, start)
if at > -1 then
    printfn $"{at}"
else
    printfn "(not found)"
(*

The first character occurrence from position 33 to 66.
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: 49

*)
' Sample for String.IndexOfAny(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 / 2
      Console.WriteLine()
      Console.WriteLine("Search for a character occurrence from position {0} to {1}.", _
                           start, str.Length - 1)
      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.IndexOfAny(anyOf, start)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.WriteLine()
   End Sub
End Class
'
'
'Search for a character occurrence from position 33 to 66.
'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: 49
'

설명

인덱스 번호 매기기 시작은 0부터 시작합니다. 매개 변수는 startIndex 문자열 instance 길이보다 0에서 1까지 다양할 수 있습니다.

검색 범위는 startIndex 문자열의 끝에서 끝까지입니다.

검색 anyOf 은 대/소문자를 구분합니다.

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

추가 정보

적용 대상

IndexOfAny(Char[], Int32, Int32)

지정된 유니코드 문자 배열에 있는 문자 중에 이 인스턴스에서 맨 처음 발견되는 문자의 0부터 시작하는 인덱스를 보고합니다. 검색은 지정된 문자 위치에서 시작하여 지정된 수의 문자 위치를 검사합니다.

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

매개 변수

anyOf
Char[]

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

startIndex
Int32

검색을 시작할 위치입니다.

count
Int32

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

반환

이 인스턴스에서 anyOf의 문자가 처음 발견된 인덱스 위치(0부터 시작)입니다. anyOf의 문자가 발견되지 않으면 -1입니다.

예외

anyOf이(가) null인 경우

count 또는 startIndex가 음수입니다.

또는

count + startIndex가 이 인스턴스의 문자 수보다 큽니다.

예제

다음 예제에서는 다른 문자열의 부분 문자열 내에서 문자열 "aid"의 문자 발생 인덱스 를 찾습니다.

// Sample for String::IndexOfAny(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) / 3;
   count = (str->Length - 1) / 4;
   Console::WriteLine();
   Console::WriteLine( "The first 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->IndexOfAny( anyOf, start, count );
   if ( at > -1 )
      Console::Write( at );
   else
      Console::Write( "(not found)" );

   Console::WriteLine();
}

/*

The first character occurrence from position 22 for 16 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.IndexOfAny(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)/3;
    count = (str.Length-1)/4;
    Console.WriteLine();
    Console.WriteLine("The first 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.IndexOfAny(anyOf, start, count);
    if (at > -1)
        Console.Write(at);
    else
        Console.Write("(not found)");
    Console.WriteLine();
    }
}
/*

The first character occurrence from position 22 for 16 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.IndexOfAny(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) / 3
let count = (str.Length - 1) / 4
printfn $"\nThe first 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.IndexOfAny(anyOf, start, count)
if at > -1 then
    printfn $"{at}"
else
    printfn "(not found)"
(*

The first character occurrence from position 22 for 16 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.IndexOfAny(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) / 3
      count =(str.Length - 1) / 4
      Console.WriteLine()
      Console.WriteLine("The first 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.IndexOfAny(anyOf, start, count)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.WriteLine()
   End Sub
End Class
'
'The first character occurrence from position 22 for 16 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
'

설명

검색은 에서 startIndex 시작하여 -1로 startIndex + count 계속됩니다. 의 startIndex + count 문자는 검색에 포함되지 않습니다.

인덱스 번호 매기기 시작은 0부터 시작합니다. 매개 변수는 startIndex 문자열 instance 길이보다 0에서 1까지 다양할 수 있습니다.

검색 anyOf 은 대/소문자를 구분합니다.

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

추가 정보

적용 대상