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 컨트롤의 텍스트에서 문자 목록의 문자가 처음 나오는 경우를 검색합니다.

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을 반환합니다. 이 예제에서는 이 메서드가 라는 richTextBox1 컨트롤과 Button 예제에 정의된 이벤트 처리기에 연결된 라는 컨트롤button1이 포함된 RichTextBox 의 클래스 Form 에 배치되어야 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 문자 목록에서 문자의 첫 번째 instance 검색하고 문자의 위치를 반환합니다. 예를 들어 문자 'Q'를 포함하는 문자 배열을 전달합니다. 컨트롤에 "The Quick Brown Fox" 텍스트가 포함된 경우 메서드는 Find 4의 값을 반환합니다. 대문자 및 소문자는 검색에서 다른 값으로 간주됩니다.

속성이 음수 값을 반환하는 경우 검색되는 문자를 컨트롤의 내용 내에서 찾을 수 없습니다. 이 메서드를 사용하여 컨트롤 내에서 문자 그룹을 검색할 수 있습니다. 이 버전의 Find 메서드를 사용하려면 컨트롤에 포함된 전체 문서가 문자를 검색해야 합니다. 메서드의 매개 변수에 제공된 문자 목록의 characterSet 문자를 찾을 경우 이 메서드에서 반환되는 값은 컨트롤에서 문자 위치의 인덱스(0부터 시작)입니다. 공백은 문자의 위치를 결정할 때 메서드에 의해 문자로 간주됩니다.

적용 대상

Find(String)

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 의 첫 번째 instance 검색 문자열의 텍스트 매개 변수에 전달 된 메서드. 검색 문자열이 에서 RichTextBox발견되면 메서드는 의 true 값을 반환하고 검색 텍스트를 강조 표시하고, 그렇지 않으면 를 반환합니다 false. 이 예제에서는 이 메서드를 라는 가 richTextBox1포함된 의 Form 클래스에 RichTextBox 배치해야 합니다.

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 전에 적절한 형식으로 바꿀 수 있습니다.

참고

를 매개 변수로 수락 string 하는 메서드는 Find 내에서 RichTextBox둘 이상의 텍스트 줄에 포함된 텍스트를 찾을 수 없습니다. 이러한 검색을 수행하면 음수 1(-1)의 값이 반환됩니다.

적용 대상

Find(Char[], Int32)

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 지정된 내의 startFindMyText 위치에서 시작됩니다. 텍스트 배열의 내용이 에 RichTextBox있으면 메서드는 찾은 값의 인덱스를 반환하고, 그렇지 않으면 -1을 반환합니다. 이 예제에서는 이 메서드가 라는 컨트롤과 Button 예제에 정의된 이벤트 처리기에 연결된 라는 richTextBox1button1 컨트롤이 포함된 RichTextBox 의 클래스 Form 에 배치되어야 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 문자 목록에서 문자의 첫 번째 instance 검색하고 문자 위치를 반환합니다. 예를 들어 문자 'Q'를 포함하는 문자 배열을 전달합니다. 컨트롤에 "The Quick Brown Fox" 텍스트가 포함된 경우 메서드는 Find 4의 값을 반환합니다. 대문자 및 소문자는 검색에서 다른 값으로 간주됩니다.

속성이 음수 값을 반환하는 경우 검색되는 문자를 컨트롤의 내용 내에서 찾을 수 없습니다. 이 메서드를 사용하여 컨트롤 내에서 문자 그룹을 검색할 수 있습니다. 메서드의 매개 변수에 제공된 문자 목록의 characterSet 문자를 찾을 경우 이 메서드에서 반환되는 값은 컨트롤에서 문자 위치의 인덱스(0부터 시작)입니다. 공백은 문자의 위치를 결정할 때 메서드에 의해 문자로 간주됩니다.

이 버전의 Find 메서드를 사용하면 매개 변수의 값을 start 지정하여 컨트롤의 텍스트 내에서 지정된 시작 위치에서 문자 집합을 검색할 수 있습니다. 값이 0이면 컨트롤 문서의 시작 부분에서 검색이 시작되어야 했음을 나타냅니다. 이 버전의 Find 메서드를 사용하여 검색 범위를 좁히면 검색할 지정된 문자가 없거나 검색에서 중요하지 않다고 이미 알고 있는 텍스트가 포함되지 않도록 할 수 있습니다.

적용 대상

Find(String, RichTextBoxFinds)

검색에 특정 옵션을 적용하여 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 의 첫 번째 instance 검색 문자열의 텍스트 매개 변수에 전달 된 메서드. 검색 문자열이 에서 RichTextBox발견되면 메서드는 의 true 값을 반환하고 텍스트를 강조 표시합니다. 그렇지 않으면 를 반환합니다 false. 또한이 예제에서는 지정 된 검색 문자열의 대/소문자 구분 검색의 옵션을 지정 합니다. 이 예제에서는 이 메서드를 라는 가 richTextBox1포함된 의 Form 클래스에 RichTextBox 배치해야 합니다.

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.Reverseoptions 열거형을 지정하여 기본 위쪽에서 아래쪽 검색 방법 대신 문서 아래쪽에서 위쪽으로 텍스트를 검색할 수 있습니다.

참고

를 매개 변수로 수락 string 하는 메서드는 Find 내에서 RichTextBox둘 이상의 텍스트 줄에 포함된 텍스트를 찾을 수 없습니다. 이러한 검색을 수행하면 음수 1(-1)의 값이 반환됩니다.

적용 대상

Find(Char[], Int32, Int32)

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 문자 목록에서 문자의 첫 번째 instance 검색하고 문자의 위치를 반환합니다. 예를 들어 문자 'Q'를 포함하는 문자 배열을 전달합니다. 컨트롤에 "The Quick Brown Fox" 텍스트가 포함된 경우 메서드는 Find 4의 값을 반환합니다. 대문자 및 소문자는 검색에서 다른 값으로 간주됩니다.

속성이 음수 값을 반환하는 경우 검색되는 문자를 컨트롤의 내용 내에서 찾을 수 없습니다. 이 메서드를 사용하여 컨트롤 내에서 문자 그룹을 검색할 수 있습니다. 메서드의 매개 변수에 제공된 문자 목록의 characterSet 문자를 찾을 경우 이 메서드에서 반환되는 값은 컨트롤에서 문자 위치의 0부터 시작하는 인덱스입니다. 공백은 문자의 위치를 결정할 때 메서드에 의해 문자로 간주됩니다.

이 버전의 Find 메서드를 사용하면 및 end 매개 변수의 값을 start 지정하여 컨트롤의 텍스트 범위에서 문자 집합을 검색할 수 있습니다. 매개 변수에 대한 값이 start 0이면 컨트롤 문서의 시작 부분에서 검색이 시작되어야 했음을 나타냅니다. 매개 변수의 -1 값은 end 검색이 컨트롤 내의 텍스트 끝에서 끝나야 했음을 나타냅니다. 이 버전을 사용할 수는 Find 애플리케이션의 요구에 맞게 중요 하지 않은 문서의 영역 검색을 방지 하려면 컨트롤 내에서 텍스트의 특정 범위로 검색 범위를 좁히려면 메서드.

적용 대상

Find(String, Int32, RichTextBoxFinds)

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 의 첫 번째 instance 검색 문자열의 텍스트 매개 변수에 전달 된 메서드. 검색 시작 위치는 메서드의 시작 매개 변수에 의해 지정 됩니다. 검색 문자열에 있으면는 RichTextBox, 그렇지 않으면-1 값을 반환 합니다; 메서드는 검색된 된 텍스트의 첫 번째 문자의 인덱스 위치를 반환 하 고 찾은 텍스트를 강조 표시 합니다. 또한이 예제에서는 지정 된 검색 문자열의 대/소문자 구분 검색의 옵션을 지정 합니다. 이 예제에서는 이 메서드를 라는 가 richTextBox1포함된 의 Form 클래스에 RichTextBox 배치해야 합니다. 이 예제를 사용하여 "다음 찾기" 유형의 작업을 수행할 수 있습니다. 검색 텍스트의 instance 찾으면 현재 일치 위치 이외의 위치에서 검색하도록 매개 변수 값을 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.Reverseoptions 열거형을 지정하여 기본 위쪽에서 아래쪽 검색 방법 대신 문서 아래쪽에서 위쪽으로 텍스트를 검색할 수 있습니다. 또한 이 버전의 Find 메서드를 사용하면 컨트롤의 텍스트 내에서 특정 시작 위치를 선택하여 텍스트 검색 범위를 좁힐 수 있습니다. 이 기능을 사용하면 이미 검색되었거나 검색 중인 특정 텍스트가 존재하지 않는 것으로 알려진 텍스트를 방지할 수 있습니다. 값이 RichTextBoxFinds.Reverse 매개 변수에 options 지정되면 매개 변수의 start 값은 이 버전의 Find 메서드를 사용할 때 문서 아래쪽에서 검색이 시작되므로 역방향 검색이 종료되는 위치를 나타냅니다.

참고

를 매개 변수로 수락 string 하는 메서드는 Find 내에서 RichTextBox둘 이상의 텍스트 줄에 포함된 텍스트를 찾을 수 없습니다. 이러한 검색을 수행하면 음수 1(-1)의 값이 반환됩니다.

적용 대상

Find(String, Int32, Int32, RichTextBoxFinds)

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 전달된 검색 문자열의 첫 번째 instance 검색합니다. 컨트롤 내에서 텍스트를 검색할 범위는 메서드의 searchStartsearchEnd 매개 변수에 의해 지정됩니다. 검색 문자열에 있으면는 RichTextBox, 그렇지 않으면-1 값을 반환 합니다; 메서드는 검색된 된 텍스트의 첫 번째 문자의 인덱스 위치를 반환 하 고 찾은 텍스트를 강조 표시 합니다. 또한 이 예제에서는 메서드의 매개 변수를 Find 사용하여 options 찾은 텍스트가 검색 문자열의 대/소문자와 일치하도록 지정합니다. 이 예제에서는 이 메서드가 라는 richTextBox1컨트롤을 포함하는 의 Form 클래스에 RichTextBox 배치되어야 합니다. 검색 문자열의 첫 번째 instance 찾은 후 이 예제를 사용하여 텍스트에서 다른 인스턴스를 찾을 수 있습니다.

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.Reverseoptions 열거형을 지정하여 기본 위쪽에서 아래쪽 검색 방법 대신 문서 아래쪽에서 위쪽으로 텍스트를 검색할 수 있습니다. 또한 이 버전의 Find 메서드를 사용하면 컨트롤의 텍스트 내에서 특정 시작 및 끝 위치를 선택하여 텍스트 검색 범위를 좁힐 수 있습니다. 이 기능을 사용하면 검색 범위를 컨트롤 텍스트의 특정 섹션으로 제한할 수 있습니다. 음수 1(-1) 값이 매개 변수에 end 할당된 경우 메서드는 에서 텍스트가 끝날 때까지 를 검색하여 일반 검색을 RichTextBox 합니다. 역방향 검색의 경우 매개 변수에 할당된 end 음수 1(-1) 값은 텍스트 끝에서 매개 변수로 정의된 start 위치까지 텍스트가 검색됨을 나타냅니다. 및 end 매개 변수가 start 동일한 값을 제공하면 전체 컨트롤이 일반 검색을 검색합니다. 역방향 검색의 경우 전체 컨트롤이 검색되지만 검색은 문서 아래쪽에서 시작하여 문서 맨 위로 검색됩니다.

참고

를 매개 변수로 수락 string 하는 메서드는 Find 내에서 RichTextBox둘 이상의 텍스트 줄에 포함된 텍스트를 찾을 수 없습니다. 이러한 검색을 수행하면 음수 1(-1)의 값이 반환됩니다.

적용 대상