RichTextBox.Find メソッド

定義

RichTextBoxの内容内のテキストを検索します。

オーバーロード

名前 説明
Find(Char[])

RichTextBox コントロールのテキストで、文字の一覧から文字の最初のインスタンスを検索します。

Find(String)

RichTextBox コントロール内の文字列を検索します。

Find(Char[], Int32)

RichTextBox コントロールのテキストを特定の開始点で検索し、文字の一覧から文字の最初のインスタンスを検索します。

Find(String, RichTextBoxFinds)

RichTextBox コントロール内のテキストで、検索に特定のオプションが適用された文字列を検索します。

Find(Char[], Int32, Int32)

RichTextBox コントロール内のテキスト範囲を検索して、文字の一覧から文字の最初のインスタンスを検索します。

Find(String, Int32, RichTextBoxFinds)

RichTextBox コントロール内のテキストを検索し、コントロール内の特定の場所にある文字列を検索し、検索に特定のオプションを適用します。

Find(String, Int32, Int32, RichTextBoxFinds)

RichTextBox コントロール内のテキストを検索し、コントロール内のテキスト範囲内の文字列を検索し、検索に特定のオプションを適用します。

Find(Char[])

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロールのテキストで、文字の一覧から文字の最初のインスタンスを検索します。

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

パラメーター

characterSet
Char[]

検索する文字の配列。

返品

検索文字が見つかったコントロール内の場所。検索文字が見つからないか、 char パラメーターに空の検索文字セットが指定されている場合に -1 します。

次のコード例では、 RichTextBox の内容を検索して、 text パラメーター内のメソッドに渡される文字を検索します。 text配列の内容がRichTextBoxで見つかった場合、メソッドは見つかった値のインデックスを返します。それ以外の場合は -1 を返します。 この例では、このメソッドを、Form という名前のRichTextBox コントロールと、richTextBox1 という名前のButton コントロールを含むbutton1のクラスに配置する必要があります。このコントロールは、この例で定義されているClick イベント ハンドラーに接続されています。

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      array<Char>^temp1 = {'D','e','l','t','a'};
      MessageBox::Show( FindMyText( temp1 ).ToString() );
   }

public:
   int FindMyText( array<Char>^text )
   {
      // Initialize the return value to false by default.
      int returnValue = -1;

      // Ensure that a search string has been specified and a valid start point.
      if ( text->Length > 0 )
      {
         // Obtain the location of the first character found in the control
         // that matches any of the characters in the char array.
         int indexToText = richTextBox1->Find( text );

         // Determine whether the text was found in richTextBox1.
         if ( indexToText >= 0 )
         {
            // Return the location of the character.
            returnValue = indexToText;
         }
      }

      return returnValue;
   }
private void button1_Click(object sender, System.EventArgs e)
{
    MessageBox.Show(FindMyText(new char[]{'D','e','l','t','a'}).ToString());
}

public int FindMyText(char[] text)
{
    // Initialize the return value to false by default.
    int returnValue = -1;

    // Ensure that a search string has been specified and a valid start point.
    if (text.Length > 0) 
    {
        // Obtain the location of the first character found in the control
        // that matches any of the characters in the char array.
        int indexToText = richTextBox1.Find(text);
        // Determine whether the text was found in richTextBox1.
        if(indexToText >= 0)
        {
            // Return the location of the character.
            returnValue = indexToText;
        }
    }

    return returnValue;
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
    MessageBox.Show(FindMyText(New Char() {"B"c, "r"c, "a"c, "v"c, "o"c}).ToString())
End Sub


Public Function FindMyText(ByVal [text]() As Char) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = -1

    ' Ensure that a search string has been specified and a valid start point.
    If [text].Length > 0 Then
        ' Obtain the location of the first character found in the control
        ' that matches any of the characters in the char array.
        Dim indexToText As Integer = richTextBox1.Find([text])
        ' Determine whether the text was found in richTextBox1.
        If indexToText >= 0 Then
            ' Return the location of the character.
            returnValue = indexToText
        End If
    End If

    Return returnValue
End Function

注釈

このバージョンの Find メソッドは、 characterSet パラメーターで指定された文字の一覧から文字の最初のインスタンスを検索し、文字の場所を返します。 たとえば、文字 'Q' を含む文字の配列を渡します。 コントロールに "The Quick Brown Fox" というテキストが含まれている場合、 Find メソッドは 4 の値を返します。 検索では、大文字と小文字が異なる値と見なされます。

プロパティが負の値を返す場合、検索対象の文字がコントロールの内容内に見つかりませんでした。 このメソッドを使用して、コントロール内の文字のグループを検索できます。 このバージョンの Find メソッドでは、コントロールに含まれるドキュメント全体で文字を検索する必要があります。 メソッドの characterSet パラメーターで指定された文字リストの文字が見つかった場合、このメソッドによって返される値は、コントロール内での文字の位置の 0 から始まるインデックスです。 スペースは、文字の位置を決定するときに、メソッドによって文字と見なされます。

適用対象

Find(String)

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロール内の文字列を検索します。

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

パラメーター

str
String

コントロール内で検索するテキスト。

返品

検索テキストが見つかったコントロール内の場所。検索文字列が見つからないか、空の検索文字列が str パラメーターに指定されている場合に -1 します。

次のコード例では、メソッドのテキスト パラメーターに渡された検索文字列の最初のインスタンスについて、 RichTextBox の内容全体を検索します。 RichTextBoxで検索文字列が見つかった場合、メソッドは true の値を返し、検索テキストを強調表示します。それ以外の場合は、falseを返します。 この例では、このメソッドを、Formという名前のRichTextBoxを含むrichTextBox1のクラスに配置する必要があります。

public:
   bool FindMyText( String^ text )
   {
      // Initialize the return value to false by default.
      bool returnValue = false;
      
      // Ensure a search string has been specified.
      if ( text->Length > 0 )
      {
         // Obtain the location of the search string in richTextBox1.
         int indexToText = richTextBox1->Find( text );
         // Determine whether the text was found in richTextBox1.
         if ( indexToText >= 0 )
         {
            returnValue = true;
         }
      }

      return returnValue;
   }
public bool FindMyText(string text)
{
   // Initialize the return value to false by default.
   bool returnValue = false;

   // Ensure a search string has been specified.
   if (text.Length > 0) 
   {
      // Obtain the location of the search string in richTextBox1.
      int indexToText = richTextBox1.Find(text);
      // Determine whether the text was found in richTextBox1.
      if(indexToText >= 0)
      {
         returnValue = true;
      }
   }

   return returnValue;
}
Public Function FindMyText(text As String) As Boolean
    ' Initialize the return value to false by default.
    Dim returnValue As Boolean = False
    
    ' Ensure a search string has been specified.
    If text.Length > 0 Then
        ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(text)
        ' Determine whether the text was found in richTextBox1.
        If indexToText >= 0 Then
            returnValue = True
        End If
    End If
    
    Return returnValue
End Function

注釈

Find メソッドは、str パラメーターで指定されたテキストを検索し、コントロール内の最初の文字の位置を返します。 プロパティが負の値を返す場合、検索対象のテキスト文字列がコントロールの内容内で見つかりませんでした。 このメソッドを使用すると、コントロールのユーザーに提供できる検索機能を作成できます。 このメソッドを使用して、特定の形式に置き換えるテキストを検索することもできます。 たとえば、ユーザーがコントロールに日付を入力した場合、コントロールのFindメソッドを使用する前に、SaveFile メソッドを使用してドキュメント内のすべての日付を検索し、適切な形式に置き換えることができます。

Note

パラメーターとしてFindを受け入れるstring メソッドは、RichTextBox内の複数行のテキストに含まれるテキストを見つけることができません。 このような検索を実行すると、負の値 (-1) が返されます。

適用対象

Find(Char[], Int32)

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロールのテキストを特定の開始点で検索し、文字の一覧から文字の最初のインスタンスを検索します。

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

パラメーター

characterSet
Char[]

検索する文字の配列。

start
Int32

検索を開始するコントロールのテキスト内の位置。

返品

検索文字が見つかったコントロール内の場所。

次のコード例では、 RichTextBox の内容を検索して、 text パラメーター内のメソッドに渡される文字を検索します。 検索は、RichTextBox メソッドの start パラメーターで指定されたFindMyText内の場所から開始されます。 RichTextBoxでテキスト配列の内容が見つかった場合、メソッドは見つかった値のインデックスを返します。それ以外の場合は -1 を返します。 この例では、このメソッドを、Form という名前のRichTextBox コントロールと、例で定義されているrichTextBox1 イベント ハンドラーに接続されている Button という名前のbutton1 コントロールを含むClickのクラスに配置する必要があります。

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      array<Char>^temp0 = {'B','r','a','v','o'};
      MessageBox::Show( FindMyText( temp0, 5 ).ToString() );
   }

public:
   int FindMyText( array<Char>^text, int start )
   {
      // Initialize the return value to false by default.
      int returnValue = -1;

      // Ensure that a valid char array has been specified and a valid start point.
      if ( text->Length > 0 && start >= 0 )
      {
         // Obtain the location of the first character found in the control
         // that matches any of the characters in the char array.
         int indexToText = richTextBox1->Find( text, start );

         // Determine whether any of the chars are found in richTextBox1.
         if ( indexToText >= 0 )
         {
            // Return the location of the character.
            returnValue = indexToText;
         }
      }

      return returnValue;
   }
private void button1_Click(object sender, System.EventArgs e)
{
    MessageBox.Show(FindMyText(new char[]{'B','r','a','v','o'}, 5).ToString());
}

public int FindMyText(char[] text, int start)
{
    // Initialize the return value to false by default.
    int returnValue = -1;

    // Ensure that a valid char array has been specified and a valid start point.
    if (text.Length > 0 && start >= 0) 
    {
        // Obtain the location of the first character found in the control
        // that matches any of the characters in the char array.
        int indexToText = richTextBox1.Find(text, start);
        // Determine whether any of the chars are found in richTextBox1.
        if(indexToText >= 0)
        {
            // Return the location of the character.
            returnValue = indexToText;
        }
    }

    return returnValue;
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
    MessageBox.Show(FindMyText(New Char() {"B"c, "r"c, "a"c, "v"c, "o"c}, 5).ToString())
End Sub


Public Function FindMyText(ByVal text() As Char, ByVal start As Integer) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = -1

    ' Ensure that a valid char array has been specified and a valid start point.
    If [text].Length > 0 And start >= 0 Then
        ' Obtain the location of the first character found in the control
        ' that matches any of the characters in the char array.
        Dim indexToText As Integer = richTextBox1.Find([text], start)
        ' Determine whether any of the chars are found in richTextBox1.
        If indexToText >= 0 Then
            ' Return the location of the character.
            returnValue = indexToText
        End If
    End If

    Return returnValue
End Function

注釈

このバージョンの Find メソッドは、 characterSet パラメーターで指定された文字の一覧から文字の最初のインスタンスを検索し、文字の場所を返します。 たとえば、文字 'Q' を含む文字の配列を渡します。 コントロールに "The Quick Brown Fox" というテキストが含まれている場合、 Find メソッドは 4 の値を返します。 検索では、大文字と小文字が異なる値と見なされます。

プロパティが負の値を返す場合、検索対象の文字がコントロールの内容内に見つかりませんでした。 このメソッドを使用して、コントロール内の文字のグループを検索できます。 メソッドの characterSet パラメーターで指定された文字リストの文字が見つかった場合、このメソッドによって返される値は、コントロール内での文字の位置の 0 から始まるインデックスです。 スペースは、文字の位置を決定するときに、メソッドによって文字と見なされます。

このバージョンの Find メソッドを使用すると、 start パラメーターの値を指定することで、コントロールのテキスト内の指定した開始位置から文字セットを検索できます。 値が 0 の場合は、コントロールのドキュメントの先頭から検索を開始する必要があることを示します。 このバージョンの Find メソッドを使用すると、検索対象の指定した文字が既に含まれていないか、検索で重要でないことがわかっているテキストを回避するために、検索を絞り込むことができます。

適用対象

Find(String, RichTextBoxFinds)

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロール内のテキストで、検索に特定のオプションが適用された文字列を検索します。

public:
 int Find(System::String ^ str, System::Windows::Forms::RichTextBoxFinds options);
public int Find(string str, System.Windows.Forms.RichTextBoxFinds options);
member this.Find : string * System.Windows.Forms.RichTextBoxFinds -> int
Public Function Find (str As String, options As RichTextBoxFinds) As Integer

パラメーター

str
String

コントロール内で検索するテキスト。

options
RichTextBoxFinds

RichTextBoxFinds値のビットごとの組み合わせ。

返品

検索テキストが見つかったコントロール内の場所。

次のコード例では、メソッドのテキスト パラメーターに渡された検索文字列の最初のインスタンスについて、 RichTextBox の内容全体を検索します。 RichTextBoxで検索文字列が見つかった場合、メソッドはtrueの値を返し、テキストを強調表示します。それ以外の場合は、falseを返します。 この例では、指定した検索文字列の大文字と小文字を一致させる検索のオプションも指定します。 この例では、このメソッドを、Formという名前のRichTextBoxを含むrichTextBox1のクラスに配置する必要があります。

public:
   bool FindMyText( String^ text )
   {
      // Initialize the return value to false by default.
      bool returnValue = false;
      
      // Ensure a search string has been specified.
      if ( text->Length > 0 )
      {
         // Obtain the location of the search string in richTextBox1.
         int indexToText = richTextBox1->Find( text, RichTextBoxFinds::MatchCase );
         // Determine if the text was found in richTextBox1.
         if ( indexToText >= 0 )
         {
            returnValue = true;
         }
      }

      return returnValue;
   }
public bool FindMyText(string text)
{
   // Initialize the return value to false by default.
   bool returnValue = false;

   // Ensure a search string has been specified.
   if (text.Length > 0) 
   {
      // Obtain the location of the search string in richTextBox1.
      int indexToText = richTextBox1.Find(text, RichTextBoxFinds.MatchCase);
      // Determine if the text was found in richTextBox1.
      if(indexToText >= 0)
      {
         returnValue = true;
      }
   }

   return returnValue;
}
Public Function FindMyText(text As String) As Boolean
    ' Initialize the return value to false by default.
    Dim returnValue As Boolean = False
    
    ' Ensure a search string has been specified.
    If text.Length > 0 Then
        ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(text, RichTextBoxFinds.MatchCase)
        ' Determine if the text was found in richTextBox1.
        If indexToText >= 0 Then
            returnValue = True
        End If
    End If
    
    Return returnValue
End Function

注釈

Find メソッドは、str パラメーターで指定されたテキストを検索し、コントロール内の最初の文字の位置を返します。 プロパティが負の値を返す場合、検索対象のテキスト文字列がコントロールの内容内で見つかりませんでした。 このメソッドを使用すると、コントロールのユーザーに提供できる検索機能を作成できます。 このメソッドを使用して、特定の形式に置き換えるテキストを検索することもできます。 たとえば、ユーザーがコントロールに日付を入力した場合、 Find メソッドを使用してドキュメント内のすべての日付を検索し、適切な形式に置き換えてから、コントロールの SaveFile メソッドを使用できます。

このバージョンの Find メソッドでは、検索を拡張または絞り込むことができるオプションを指定できます。 検索語の大文字と小文字を一致させたり、部分的な単語ではなく単語全体を検索したりするためのオプションを指定できます。 RichTextBoxFinds.Reverse パラメーターでoptions列挙体を指定すると、既定の上から下の検索方法ではなく、ドキュメントの下部から先頭にテキストを検索できます。

Note

パラメーターとしてFindを受け入れるstring メソッドは、RichTextBox内の複数行のテキストに含まれるテキストを見つけることができません。 このような検索を実行すると、負の値 (-1) が返されます。

適用対象

Find(Char[], Int32, Int32)

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロール内のテキスト範囲を検索して、文字の一覧から文字の最初のインスタンスを検索します。

public:
 int Find(cli::array <char> ^ characterSet, int start, int end);
public int Find(char[] characterSet, int start, int end);
member this.Find : char[] * int * int -> int
Public Function Find (characterSet As Char(), start As Integer, end As Integer) As Integer

パラメーター

characterSet
Char[]

検索する文字の配列。

start
Int32

検索を開始するコントロールのテキスト内の位置。

end
Int32

検索を終了するコントロールのテキスト内の位置。

返品

検索文字が見つかったコントロール内の場所。

例外

characterSet が null です。

start が 0 より小さいか、コントロール内のテキストの長さを超えています。

注釈

このバージョンの Find メソッドは、 characterSet パラメーターで指定された文字の一覧から文字の最初のインスタンスを検索し、文字の場所を返します。 たとえば、文字 'Q' を含む文字の配列を渡します。 コントロールに "The Quick Brown Fox" というテキストが含まれている場合、 Find メソッドは 4 の値を返します。 検索では、大文字と小文字が異なる値と見なされます。

プロパティが負の値を返す場合、検索対象の文字がコントロールの内容内に見つかりませんでした。 このメソッドを使用して、コントロール内の文字のグループを検索できます。 メソッドの characterSet パラメーターで指定された文字リストの文字が見つかった場合、このメソッドによって返される値は、コントロール内の文字の位置の 0 から始まるインデックスになります。 スペースは、文字の位置を決定するときに、メソッドによって文字と見なされます。

このバージョンの Find メソッドを使用すると、 start パラメーターと end パラメーターの値を指定することで、コントロール内のテキスト範囲から文字セットを検索できます。 start パラメーターの値が 0 の場合は、コントロールのドキュメントの先頭から検索を開始する必要があることを示します。 end パラメーターの -1 値は、検索がコントロール内のテキストの末尾で終了することを示します。 このバージョンの Find メソッドを使用すると、アプリケーションのニーズに重要ではないドキュメントの領域を検索しないように、コントロール内の特定のテキスト範囲に検索を絞り込むことができます。

適用対象

Find(String, Int32, RichTextBoxFinds)

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロール内のテキストを検索し、コントロール内の特定の場所にある文字列を検索し、検索に特定のオプションを適用します。

public:
 int Find(System::String ^ str, int start, System::Windows::Forms::RichTextBoxFinds options);
public int Find(string str, int start, System.Windows.Forms.RichTextBoxFinds options);
member this.Find : string * int * System.Windows.Forms.RichTextBoxFinds -> int
Public Function Find (str As String, start As Integer, options As RichTextBoxFinds) As Integer

パラメーター

str
String

コントロール内で検索するテキスト。

start
Int32

検索を開始するコントロールのテキスト内の位置。

options
RichTextBoxFinds

RichTextBoxFinds値のビットごとの組み合わせ。

返品

検索テキストが見つかったコントロール内の場所。

次のコード例では、メソッドのテキスト パラメーターに渡された検索文字列の最初のインスタンスについて、 RichTextBox の内容全体を検索します。 検索の開始位置は、メソッドの start パラメーターで指定します。 検索文字列が RichTextBoxで見つかった場合、メソッドは見つかったテキストの最初の文字のインデックス位置を返し、見つかったテキストを強調表示します。それ以外の場合は、-1 の値を返します。 この例では、指定した検索文字列の大文字と小文字を一致させる検索のオプションも指定します。 この例では、このメソッドを、Formという名前のRichTextBoxを含むrichTextBox1のクラスに配置する必要があります。 この例を使用して、"次を検索" の種類の操作を実行できます。 検索テキストのインスタンスが見つかったら、 start パラメーターの値を変更して、現在の一致位置を超える場所で検索することで、テキストの他のインスタンスを見つけることができます。

public:
   int FindMyText( String^ text, int start )
   {
      // Initialize the return value to false by default.
      int returnValue = -1;
      
      // Ensure that a search string has been specified and a valid start point.
      if ( text->Length > 0 && start >= 0 )
      {
         // Obtain the location of the search string in richTextBox1.
         int indexToText = richTextBox1->Find( text, start, RichTextBoxFinds::MatchCase );
         // Determine whether the text was found in richTextBox1.
         if ( indexToText >= 0 )
         {
            returnValue = indexToText;
         }
      }

      return returnValue;
   }
public int FindMyText(string text, int start)
{
   // Initialize the return value to false by default.
   int returnValue = -1;

   // Ensure that a search string has been specified and a valid start point.
   if (text.Length > 0 && start >= 0) 
   {
      // Obtain the location of the search string in richTextBox1.
      int indexToText = richTextBox1.Find(text, start, RichTextBoxFinds.MatchCase);
      // Determine whether the text was found in richTextBox1.
      if(indexToText >= 0)
      {
         returnValue = indexToText;
      }
   }

   return returnValue;
}
Public Function FindMyText(text As String, start As Integer) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = - 1
    
    ' Ensure that a search string has been specified and a valid start point.
    If text.Length > 0 And start >= 0 Then
        ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(text, start, _
            RichTextBoxFinds.MatchCase)
        ' Determine whether the text was found in richTextBox1.
        If indexToText >= 0 Then
            returnValue = indexToText
        End If
    End If
    
    Return returnValue
End Function

注釈

Find メソッドは、str パラメーターで指定されたテキストを検索し、コントロール内の検索文字列の最初の文字の位置を返します。 プロパティが負の値を返す場合、検索対象のテキスト文字列がコントロールの内容内で見つかりませんでした。 このメソッドを使用すると、コントロールのユーザーに提供できる検索機能を作成できます。 このメソッドを使用して、特定の形式に置き換えるテキストを検索することもできます。 たとえば、ユーザーがコントロールに日付を入力した場合、コントロールのFindメソッドを使用する前に、SaveFile メソッドを使用してドキュメント内のすべての日付を検索し、適切な形式に置き換えることができます。

このバージョンの Find メソッドでは、検索を拡張または絞り込むことができるオプションを指定できます。 検索語の大文字と小文字を一致させたり、部分的な単語ではなく単語全体を検索したりするためのオプションを指定できます。 RichTextBoxFinds.Reverse パラメーターでoptions列挙体を指定すると、既定の上から下の検索方法ではなく、ドキュメントの下部から先頭にテキストを検索できます。 このバージョンの Find メソッドでは、コントロールのテキスト内の特定の開始位置を選択して、テキストの検索を絞り込むこともできます。 この機能を使用すると、既に検索されているテキストや、検索する特定のテキストが存在しないことが判明しているテキストを回避できます。 RichTextBoxFinds.Reverse パラメーターでoptions値を指定した場合、start パラメーターの値は、このバージョンの Find メソッドを使用するときに、ドキュメントの下部から検索が開始されるため、逆引き検索が終了する位置を示します。

Note

パラメーターとしてFindを受け入れるstring メソッドは、RichTextBox内の複数行のテキストに含まれるテキストを見つけることができません。 このような検索を実行すると、負の値 (-1) が返されます。

適用対象

Find(String, Int32, Int32, RichTextBoxFinds)

ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs
ソース:
RichTextBox.cs

RichTextBox コントロール内のテキストを検索し、コントロール内のテキスト範囲内の文字列を検索し、検索に特定のオプションを適用します。

public:
 int Find(System::String ^ str, int start, int end, System::Windows::Forms::RichTextBoxFinds options);
public int Find(string str, int start, int end, System.Windows.Forms.RichTextBoxFinds options);
member this.Find : string * int * int * System.Windows.Forms.RichTextBoxFinds -> int
Public Function Find (str As String, start As Integer, end As Integer, options As RichTextBoxFinds) As Integer

パラメーター

str
String

コントロール内で検索するテキスト。

start
Int32

検索を開始するコントロールのテキスト内の位置。

end
Int32

検索を終了するコントロールのテキスト内の位置。 この値は、負の 1 (-1) または start パラメーター以上である必要があります。

options
RichTextBoxFinds

RichTextBoxFinds値のビットごとの組み合わせ。

返品

検索テキストが見つかったコントロール内の場所。

例外

str パラメーターがnullされました。

start パラメーターが 0 未満でした。

-又は-

end パラメーターは、start パラメーターより小さくなっています。

次のコード例では、メソッドの RichTextBox パラメーターに渡された検索文字列の最初のインスタンスについて、searchText内のテキストのセクションを検索します。 コントロール内のテキストを検索する範囲は、メソッドの searchStart パラメーターと searchEnd パラメーターによって指定されます。 検索文字列が RichTextBoxで見つかった場合、メソッドは見つかったテキストの最初の文字のインデックス位置を返し、見つかったテキストを強調表示します。それ以外の場合は、-1 の値を返します。 この例では、options メソッドの Find パラメーターを使用して、見つかったテキストが検索文字列の大文字と小文字を一致させる必要があることを指定します。 この例では、このメソッドを、Form という名前のRichTextBox コントロールを含むrichTextBox1のクラスに配置する必要があります。 検索文字列の最初のインスタンスが見つかったら、この例を使用してテキスト内の他のインスタンスを検索できます。

public:
   int FindMyText( String^ searchText, int searchStart, int searchEnd )
   {
      // Initialize the return value to false by default.
      int returnValue = -1;

      // Ensure that a search string and a valid starting point are specified.
      if ( searchText->Length > 0 && searchStart >= 0 )
      {
         // Ensure that a valid ending value is provided.
         if ( searchEnd > searchStart || searchEnd == -1 )
         {
            // Obtain the location of the search string in richTextBox1.
            int indexToText = richTextBox1->Find( searchText, searchStart, searchEnd, RichTextBoxFinds::MatchCase );

            // Determine whether the text was found in richTextBox1.
            if ( indexToText >= 0 )
            {
               // Return the index to the specified search text.
               returnValue = indexToText;
            }
         }
      }

      return returnValue;
   }
public int FindMyText(string searchText, int searchStart, int searchEnd)
{
    // Initialize the return value to false by default.
    int returnValue = -1;

    // Ensure that a search string and a valid starting point are specified.
    if (searchText.Length > 0 && searchStart >= 0) 
    {
        // Ensure that a valid ending value is provided.
        if (searchEnd > searchStart || searchEnd == -1)
        {	
            // Obtain the location of the search string in richTextBox1.
            int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase);
            // Determine whether the text was found in richTextBox1.
            if(indexToText >= 0)
            {
                // Return the index to the specified search text.
                returnValue = indexToText;
            }
        }
    }

    return returnValue;
}
Public Function FindMyText(ByVal searchText As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = -1

    ' Ensure that a search string and a valid starting point are specified.
    If searchText.Length > 0 And searchStart >= 0 Then
        ' Ensure that a valid ending value is provided.
        If searchEnd > searchStart Or searchEnd = -1 Then
            ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase)
            ' Determine whether the text was found in richTextBox1.
            If indexToText >= 0 Then
                ' Return the index to the specified search text.
                returnValue = indexToText
            End If
        End If
    End If

    Return returnValue
End Function

注釈

Find メソッドは、str パラメーターで指定されたテキストを検索し、コントロール内の検索文字列の最初の文字の位置を返します。 プロパティが負の値を返す場合、検索対象のテキスト文字列がコントロールの内容内で見つかりませんでした。 このメソッドを使用すると、コントロールのユーザーに提供できる検索機能を作成できます。 このメソッドを使用して、特定の形式に置き換えるテキストを検索することもできます。 たとえば、ユーザーがコントロールに日付を入力した場合、 Find メソッドを使用してドキュメント内のすべての日付を検索し、適切な形式に置き換えてから、コントロールの SaveFile メソッドを使用できます。

このバージョンの Find メソッドでは、検索を拡張または絞り込むことができるオプションを指定できます。 検索語の大文字と小文字を一致させたり、部分的な単語ではなく単語全体を検索したりするためのオプションを指定できます。 RichTextBoxFinds.Reverse パラメーターでoptions列挙体を指定すると、既定の上から下の検索方法ではなく、ドキュメントの下部から先頭にテキストを検索できます。 このバージョンの Find メソッドでは、コントロールのテキスト内の特定の開始位置と終了位置を選択して、テキストの検索を絞り込むこともできます。 この機能を使用すると、検索範囲をコントロールのテキストの特定のセクションに制限できます。 負の値 (-1) が end パラメーターに割り当てられている場合、メソッドは通常の検索のために RichTextBox のテキストの末尾まで検索します。 逆検索の場合、 end パラメーターに負の値 (-1) が割り当てられると、テキストがテキストの末尾 (下部) からパラメーターで定義された位置まで検索 start 示されます。 startパラメーターとend パラメーターに同じ値を指定すると、コントロール全体で通常の検索が検索されます。 逆検索の場合、コントロール全体が検索されますが、検索はドキュメントの下部から開始され、ドキュメントの先頭まで検索されます。

Note

パラメーターとしてFindを受け入れるstring メソッドは、RichTextBox内の複数行のテキストに含まれるテキストを見つけることができません。 このような検索を実行すると、負の値 (-1) が返されます。

適用対象