RichTextBox.Find 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
搜尋 RichTextBox.
多載
| 名稱 | Description |
|---|---|
| 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 中搜尋 a 中傳遞給方法 text 的字元。 若陣列內容 text 在 RichTextBox中,方法回傳該值的索引;否則回傳 -1。 範例要求此方法置於包含一個名為 控制項的 a 類別Form中,且一個RichTextBox名為 richTextBox1的控制項與範例中定義的事件處理程序相連Button。button1Click
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 方法會回傳四。 大寫字母與小寫字母在搜尋中被視為不同的值。
若屬性回傳負值,表示被搜尋的字元未在控制項內容中找到。 你可以用這個方法在控制範圍內搜尋一組字元。 此版本 Find 的方法要求搜尋控制項中整個文件的字元。 若找到方法參數中字 characterSet 元列表中的字元,該方法回傳的值即為該字元在控制項中位置的零索引。 在確定字元位置時,該方法將空間視為字元。
適用於
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
在控制面板中找到文字。
傳回
控制項中搜尋文字被找到的位置,或 -1 若找不到搜尋字串或參數中 str 指定空搜尋字串則為該位置。
範例
以下程式碼範例搜尋 的 RichTextBox 全部內容,尋找第一個傳入該方法文字參數的搜尋字串實例。 若搜尋字串在 中 RichTextBox,方法會回傳 值 true 並標示搜尋文字,否則返回 false。 範例要求將此方法置於包含Form一個命名 RichTextBox的 的 a 類別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 中,從特定起始點搜尋字元列表中的第一個字元實例。
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 中搜尋 a 中傳遞給方法 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 方法會回傳四。 大寫字母與小寫字母在搜尋中被視為不同的值。
若屬性回傳負值,表示被搜尋的字元未在控制項內容中找到。 你可以用這個方法在控制範圍內搜尋一組字元。 若找到方法參數中字 characterSet 元列表中的字元,該方法回傳的值即為該字元在控制項中位置的零索引。 在確定字元位置時,該方法將空間視為字元。
此版本 Find 的方法允許你從控制項文本中指定的起始位置搜尋字元集,並指定參數值 start 。 值為零表示搜尋應從控制文件的開頭開始。 你可以利用此版本 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 全部內容,尋找第一個傳入該方法文字參數的搜尋字串實例。 若搜尋字串在 RichTextBox中,方法會回傳 值 true 並標示該文字;否則,返回 false。 範例中也指定搜尋選項以符合指定搜尋字串的情況。 範例要求將此方法置於包含Form一個命名 RichTextBox的 的 a 類別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 控制項中搜尋字元列表中第一個字元實例。
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 方法會回傳四。 大寫字母與小寫字母在搜尋中被視為不同的值。
若屬性回傳負值,表示被搜尋的字元未在控制項內容中找到。 你可以用這個方法在控制範圍內搜尋一組字元。 若找到方法參數中字 characterSet 元列表中的字元,該方法回傳的值即為該字元在控制項中位置的零基索引。 在確定字元位置時,該方法將空間視為字元。
此版本Find方法允許你從控制項中的文字範圍中搜尋字元集,方法是指定參數的值startend。 參數值為零 start 表示搜尋應從控制文件的開頭開始。 參數的 -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 全部內容,尋找第一個傳入該方法文字參數的搜尋字串實例。 搜尋起始位置由方法的起始參數指定。 若搜尋字串在 , RichTextBox方法會回傳找到文字第一個字元的索引位置並標示找到文字;否則,回傳值為 -1。 範例中也指定搜尋選項以符合指定搜尋字串的情況。 範例要求將此方法置於包含Form一個命名 RichTextBox的 的 a 類別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 字串,範圍內的文字,並套用特定選項。
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)或大於或等於參數。start
- options
- RichTextBoxFinds
這是數值的位元組合 RichTextBoxFinds 。
傳回
搜尋文字在控制範圍內的位置。
例外狀況
參數 str 為 null。
範例
以下程式碼範例是在 中 RichTextBox 搜尋第一個輸入 searchText 方法參數的搜尋字串實例。 控制項內搜尋文字的範圍由 searchStart 方法的 與 searchEnd 參數指定。 若搜尋字串在 , RichTextBox方法會回傳找到文字第一個字元的索引位置並標示找到文字;否則,回傳值為 -1。 範例也使用 options 方法參數 Find 指定找到的文字應與搜尋字串的案例相符。 範例要求此方法必須置於包含Form名為 RichTextBox的控制項的 a 類別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 還能透過控制項文字中選擇特定起始與結束位置,縮小搜尋範圍。 此功能可將搜尋範圍限制於控制項文字的特定區塊。 若參數值 end 為負一(-1),則該方法會搜尋到文字末 RichTextBox 尾,以進行正常搜尋。 對於反向搜尋,參數值 end 為負一(-1),表示將從文字末尾(底部)搜尋到參數 start 定義的位置。 當 start 和 end 參數值相同時,整個控制項會被搜尋以進行正常搜尋。 反向搜尋則會搜尋整個控制項,但搜尋從文件底部開始,搜尋到文件頂部。
Note
Find接受 參數string的方法無法找到包含於 中多行文字RichTextBox的文字。 執行此類搜尋會回傳負一的值(-1)。