ListBox.FindStringExact 메서드

정의

지정된 문자열과 정확히 일치하는 ListBox의 첫째 항목을 찾습니다.

오버로드

FindStringExact(String)

지정된 문자열과 정확히 일치하는 ListBox의 첫째 항목을 찾습니다.

FindStringExact(String, Int32)

지정된 문자열과 정확히 일치하는 ListBox의 첫째 항목을 찾습니다. 검색은 특정 시작 인덱스에서 시작됩니다.

FindStringExact(String)

지정된 문자열과 정확히 일치하는 ListBox의 첫째 항목을 찾습니다.

public:
 int FindStringExact(System::String ^ s);
public int FindStringExact (string s);
member this.FindStringExact : string -> int
Public Function FindStringExact (s As String) As Integer

매개 변수

s
String

검색할 텍스트입니다.

반환

Int32

찾은 첫째 항목의 인덱스(0부터 시작)입니다. 일치하는 항목이 없으면 ListBox.NoMatches를 반환합니다.

예제

다음 코드 예제에서는 메서드를 사용하여 ListBox.FindStringExact 지정된 문자열과 정확히 일치하는 항목에 대한 컨트롤을 검색 ListBox 하는 방법을 보여 줍니다. 검색 문자열 FindStringExact 과 일치하는 항목을 찾을 수 없으면 -1 값을 반환하고 예제에서 다음을 MessageBox표시합니다. 검색 텍스트와 일치하는 항목이 발견되면 이 예제에서는 메서드를 SetSelected 사용하여 에서 ListBox항목을 선택합니다.

private:
   void FindMySpecificString( String^ searchString )
   {
      // Ensure we have a proper string to search for.
      if ( searchString != String::Empty )
      {
         // Find the item in the list and store the index to the item.
         int index = listBox1->FindStringExact( searchString );

         // Determine if a valid index is returned. Select the item if it is valid.
         if ( index != ListBox::NoMatches )
                  listBox1->SetSelected( index, true );
         else
                  MessageBox::Show( "The search string did not find any items in the ListBox that exactly match the specified search string" );
      }
   }
private void FindMySpecificString(string searchString)
{
   // Ensure we have a proper string to search for.
   if (!string.IsNullOrEmpty(searchString))
   {
      // Find the item in the list and store the index to the item.
      int index = listBox1.FindStringExact(searchString);
      // Determine if a valid index is returned. Select the item if it is valid.
      if (index != ListBox.NoMatches)
         listBox1.SetSelected(index,true);
      else
         MessageBox.Show("The search string did not find any items in the ListBox that exactly match the specified search string");
   }
}
Private Sub FindMySpecificString(ByVal searchString As String)
   ' Ensure we have a proper string to search for.
   If searchString <> String.Empty Then
      ' Find the item in the list and store the index to the item.
      Dim index As Integer = listBox1.FindStringExact(searchString)
      ' Determine if a valid index is returned. Select the item if it is valid.
      If index <> ListBox.NoMatches Then
         listBox1.SetSelected(index, True)
      Else
         MessageBox.Show("The search string did not find any items in the ListBox that exactly match the specified search string")
      End If
   End If
End Sub

설명

이 메서드에서 수행하는 검색은 대/소문자를 구분하지 않습니다. 검색은 검색 문자열 매개 변수 s에 지정된 단어와 정확히 일치하는 항목을 찾습니다. 이 메서드를 사용하여 지정된 문자열과 일치하는 첫 번째 항목을 검색할 수 있습니다. 그런 다음, 메서드를 사용 Remove 하거나 항목의 텍스트를 변경하여 검색 텍스트가 포함된 항목을 제거하는 등의 작업을 수행할 수 있습니다. 지정한 텍스트를 찾은 후 텍스트의 ListBox다른 인스턴스를 검색하려는 경우 내의 시작 인덱ListBox스를 지정하기 위한 매개 변수를 제공하는 메서드의 FindStringExact 버전을 사용할 수 있습니다. 정확한 단어 일치 대신 부분 단어 검색을 수행하려면 이 메서드를 FindString 사용합니다.

추가 정보

적용 대상

FindStringExact(String, Int32)

지정된 문자열과 정확히 일치하는 ListBox의 첫째 항목을 찾습니다. 검색은 특정 시작 인덱스에서 시작됩니다.

public:
 int FindStringExact(System::String ^ s, int startIndex);
public int FindStringExact (string s, int startIndex);
member this.FindStringExact : string * int -> int
Public Function FindStringExact (s As String, startIndex As Integer) As Integer

매개 변수

s
String

검색할 텍스트입니다.

startIndex
Int32

검색될 첫째 항목 앞에 나오는 항목의 0부터 시작하는 인덱스입니다. 컨트롤의 처음부터 검색하려면 -1로 설정합니다.

반환

Int32

찾은 첫째 항목의 인덱스(0부터 시작)입니다. 일치하는 항목이 없으면 ListBox.NoMatches를 반환합니다.

예외

startIndex 매개 변수가 0보다 작거나 Count 클래스의 ListBox.ObjectCollection 속성 값보다 크거나 같은 경우

예제

다음 코드 예제에서는 메서드를 사용하여 FindStringExact 지정된 검색 텍스트와 정확히 일치하는 모든 항목을 ListBox 검색하는 방법을 보여 줍니다. 이 예제에서는 모든 항목을 ListBox지속적으로 검색할 시작 검색 인덱스를 지정할 수 있는 메서드의 버전을 FindStringExact 사용합니다. 이 예제에서는 재귀 검색을 방지하기 위해 항목 목록의 맨 아래에 도달한 후 메서드가 목록 맨 위에서 검색을 시작하는 시점을 확인하는 FindStringExact 방법도 보여 줍니다. 항목이 ListBox발견되면 메서드를 사용하여 SetSelected 선택됩니다.

private:
   void FindAllOfMyExactStrings( String^ searchString )
   {
      // Set the SelectionMode property of the ListBox to select multiple items.
      listBox1->SelectionMode = SelectionMode::MultiExtended;

      // Set our intial index variable to -1.
      int x = -1;

      // If the search string is empty exit.
      if ( searchString->Length != 0 )
      {
         // Loop through and find each item that matches the search string.
         do
         {
            // Retrieve the item based on the previous index found. Starts with -1 which searches start.
            x = listBox1->FindStringExact( searchString, x );

            // If no item is found that matches exit.
            if ( x != -1 )
            {
               // Since the FindStringExact loops infinitely, determine if we found first item again and exit.
               if ( listBox1->SelectedIndices->Count > 0 )
               {
                  if ( x == listBox1->SelectedIndices[ 0 ] )
                                    return;
               }

               // Select the item in the ListBox once it is found.
               listBox1->SetSelected( x, true );
            }
         }
         while ( x != -1 );
      }
   }
private void FindAllOfMyExactStrings(string searchString)
{
   // Set the SelectionMode property of the ListBox to select multiple items.
   listBox1.SelectionMode = SelectionMode.MultiExtended;
   
   // Set our intial index variable to -1.
   int x =-1;
   // If the search string is empty exit.
   if (searchString.Length != 0)
   {
      // Loop through and find each item that matches the search string.
      do
      {
         // Retrieve the item based on the previous index found. Starts with -1 which searches start.
         x = listBox1.FindStringExact(searchString, x);
         // If no item is found that matches exit.
         if (x != -1)
         {
            // Since the FindStringExact loops infinitely, determine if we found first item again and exit.
            if (listBox1.SelectedIndices.Count > 0)
            {
               if (x == listBox1.SelectedIndices[0])
                  return;
            }
            // Select the item in the ListBox once it is found.
            listBox1.SetSelected(x,true);
         }
      }while(x != -1);
   }
}
Private Sub FindAllOfMyExactStrings(ByVal searchString As String)
   ' Set the SelectionMode property of the ListBox to select multiple items.
   ListBox1.SelectionMode = SelectionMode.MultiExtended

   ' Set our intial index variable to -1.
   Dim x As Integer = -1
   ' If the search string is empty exit.
   If searchString.Length <> 0 Then
      ' Loop through and find each item that matches the search string.
      Do
         ' Retrieve the item based on the previous index found. Starts with -1 which searches start.
         x = ListBox1.FindStringExact(searchString, x)
         ' If no item is found that matches exit.
         If x <> -1 Then
            ' Since the FindStringExact loops infinitely, determine if we found first item again and exit.
            If ListBox1.SelectedIndices.Count > 0 Then
               If x = ListBox1.SelectedIndices(0) Then
                  Return
               End If
            End If
            ' Select the item in the ListBox once it is found.
            ListBox1.SetSelected(x, True)
         End If
      Loop While x <> -1
   End If
End Sub

설명

이 메서드에서 수행하는 검색은 대/소문자를 구분하지 않습니다. 검색은 지정된 검색 문자열 매개 변수 s와 정확히 일치하는 단어를 찾습니다. 이 메서드를 사용하여 항목 목록 내의 지정된 시작 인덱스에서 지정된 문자열과 일치하는 첫 번째 항목을 ListBox검색할 수 있습니다. 그런 다음 메서드를 사용하여 Remove 검색 텍스트가 포함된 항목을 제거하거나 항목의 텍스트를 변경하는 등의 작업을 수행할 수 있습니다. 이 메서드는 일반적으로 시작 인덱스 지정 하지 않는이 메서드의 버전을 사용 하 여 호출 된 후 사용 합니다. 목록에서 초기 항목이 발견되면 이 메서드는 일반적으로 검색 텍스트의 첫 번째 검색 인스턴스 뒤 항목 매개 변수에서 startIndex 인덱스 위치를 지정하여 검색 텍스트의 추가 인스턴스를 찾는 데 사용됩니다. 정확한 단어 일치 대신 부분 단어 검색을 수행하려면 이 메서드를 FindString 사용합니다.

참고

검색이 맨 아래에 ListBox도달하면 맨 위에서 ListBox 매개 변수로 지정된 항목까지 검색을 startIndex 계속합니다.

추가 정보

적용 대상