共用方式為


TextSelection.FindText(String, Int32) Method

Definition

Searches for the given text from the active point to the end of the document. This API has been deprecated in VS 2022 and above. Please refer the breaking API changes in VS 2022 for guidance on how to migrate API usage via modern find and repalce APIs.

bool FindText(std::wstring const & Pattern, int vsFindOptionsValue = 0);
[System.Runtime.InteropServices.DispId(70)]
public bool FindText (string Pattern, int vsFindOptionsValue = 0);
[<System.Runtime.InteropServices.DispId(70)>]
abstract member FindText : string * int -> bool
Public Function FindText (Pattern As String, Optional vsFindOptionsValue As Integer = 0) As Boolean

Parameters

Pattern
String

Required. The text to find.

vsFindOptionsValue
Int32

Optional. A vsFindOptions constant indicating the search options to use.

Returns

A Boolean value indicating true if the text is found, false if not.

Attributes

Examples

Sub FindTextExample()  
   ' Before running this example, open a text document.  
   Dim objSel As TextSelection = DTE.ActiveDocument.Selection  

   ' Looks for the first occurence of the word, test, in the current   
   ' document. If found, the line is selected.  
   If objSel.FindText("test", vsFindOptions.vsFindOptionsFromStart) Then  
      objSel.SelectLine()  
   End If  
End Sub  

Remarks

FindText searches for the given text string from the text selection's active end to the end of the text document. The return value indicates whether the text is found. If the text is found, the edit point is moved to the beginning of the match. Otherwise, the edit location is unchanged.

If the matched pattern is a regular expression and contains tagged subexpressions, then the Tags argument returns a collection of TextRange objects, one for each tagged subexpression.

Applies to