ListBox.FindStringExact Yöntem

Tanım

içinde belirtilen dizeyle ListBox tam olarak eşleşen ilk öğeyi bulur.

Aşırı Yüklemeler

Name Description
FindStringExact(String)

içinde belirtilen dizeyle ListBox tam olarak eşleşen ilk öğeyi bulur.

FindStringExact(String, Int32)

içinde belirtilen dizeyle ListBox tam olarak eşleşen ilk öğeyi bulur. Arama belirli bir başlangıç dizininde başlar.

FindStringExact(String)

Kaynak:
ListBox.cs
Kaynak:
ListBox.cs
Kaynak:
ListBox.cs
Kaynak:
ListBox.cs
Kaynak:
ListBox.cs

içinde belirtilen dizeyle ListBox tam olarak eşleşen ilk öğeyi bulur.

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

Parametreler

s
String

Aranacak metin.

Döndürülenler

Bulunan ilk öğenin sıfır tabanlı dizini; eşleşme bulunamazsa döndürür ListBox.NoMatches .

Örnekler

Aşağıdaki kod örneği, belirtilen dizeyle ListBox.FindStringExact tam olarak eşleşen bir öğe için denetim ListBox aramak için yönteminin nasıl kullanılacağını gösterir. Arama dizesiyle eşleşen hiçbir öğe bulunmazsa, FindStringExact bir -1 değeri döndürür ve örnekte bir MessageBoxgörüntülenir. Arama metniyle eşleşen bir öğe bulunursa, örnekte içindeki öğeyi SetSelectedseçmek için yöntemi kullanılırListBox.

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

Açıklamalar

Bu yöntem tarafından gerçekleştirilen arama büyük/küçük harfe duyarlı değildir. Arama, arama dizesi parametresinde sbelirtilen sözcüklerle tam eşleşme arar. Belirtilen dizeyle eşleşen ilk öğeyi aramak için bu yöntemi kullanabilirsiniz. Ardından yöntemini kullanarak Remove veya öğenin metnini değiştirerek arama metnini içeren öğeyi kaldırma gibi görevleri gerçekleştirebilirsiniz. Belirtilen metni bulduğunuzda, içindeki ListBoxmetnin diğer örneklerini aramak istiyorsanız, içinde bir başlangıç dizini belirtmek için bir parametre sağlayan yöntemin FindStringExactListBoxsürümünü kullanabilirsiniz. Tam sözcük eşleşmesi yerine kısmi sözcük araması yapmak istiyorsanız yöntemini kullanın FindString .

Ayrıca bkz.

Şunlara uygulanır

FindStringExact(String, Int32)

Kaynak:
ListBox.cs
Kaynak:
ListBox.cs
Kaynak:
ListBox.cs
Kaynak:
ListBox.cs
Kaynak:
ListBox.cs

içinde belirtilen dizeyle ListBox tam olarak eşleşen ilk öğeyi bulur. Arama belirli bir başlangıç dizininde başlar.

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

Parametreler

s
String

Aranacak metin.

startIndex
Int32

Aranacak ilk öğeden önceki öğenin sıfır tabanlı dizini. Denetimin başından arama yapmak için negatif bir (-1) olarak ayarlayın.

Döndürülenler

Bulunan ilk öğenin sıfır tabanlı dizini; eşleşme bulunamazsa döndürür ListBox.NoMatches .

Özel durumlar

startIndex parametresi sıfırdan küçük veya sınıfın özelliğinin CountListBox.ObjectCollection değerine eşit veya sıfırdan büyük.

Örnekler

Aşağıdaki kod örneği, belirtilen arama metniyle FindStringExact tam olarak eşleşen bir ListBox içindeki tüm öğeleri aramak için yönteminin nasıl kullanılacağını gösterir. Örnek, içindeki tüm öğeleri sürekli olarak aramak için başlangıç arama dizini belirtmenizi sağlayan yönteminin FindStringExactsürümünü ListBox kullanır. Örnek ayrıca özyinelemeli bir aramayı önlemek için yöntemin öğe listesinin en altına ulaştıktan sonra listenin en üstünden aramaya ne zaman FindStringExact başladığını belirlemeyi de gösterir. öğeleri içinde ListBoxbulunduktan sonra yöntemi kullanılarak SetSelected seçilir.

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

Açıklamalar

Bu yöntem tarafından gerçekleştirilen arama büyük/küçük harfe duyarlı değildir. Arama, belirtilen arama dizesi parametresiyle stam olarak eşleşen sözcükleri arar. Bu yöntemi, öğesi listesinde belirtilen başlangıç dizininde belirtilen dizeyle eşleşen ilk öğeyi aramak için ListBoxkullanabilirsiniz. Daha sonra yöntemini kullanarak Remove arama metnini içeren öğeyi kaldırma gibi görevleri gerçekleştirebilir veya öğenin metnini değiştirebilirsiniz. Bu yöntem genellikle bu yöntemin başlangıç dizini belirtmeyen sürümü kullanılarak bir çağrı yapıldıktan sonra kullanılır. Listede ilk öğe bulunduktan sonra bu yöntem genellikle arama metninin ilk bulunan örneğinden sonra öğenin parametresindeki startIndex dizin konumunu belirterek arama metninin diğer örneklerini bulmak için kullanılır. Tam sözcük eşleşmesi yerine kısmi sözcük araması yapmak istiyorsanız yöntemini kullanın FindString .

Note

Arama öğesinin en altına ListBoxulaştığında, gerinin en üstünden ListBox parametresi tarafından startIndex belirtilen öğeye kadar aramaya devam eder.

Ayrıca bkz.

Şunlara uygulanır