FindPattern Method (TextSelection Object)
Searches for the given pattern from the active point to the end of the document.
Public Function FindPattern( _ ByVal Pattern As String, _ Optional ByVal Flags As Integer = 0, _ Optional ByRef Tags As TextRanges = Nothing _ ) As Boolean
Function FindPattern( _ ByVal Pattern As String, _ Optional ByVal Flags As Long = 0, _ Optional ByRef Tags As TextRanges = Nothing _ ) As Boolean
HRESULT __stdcall FindPattern( BSTR Pattern, long Flags, TextRanges** Tags, /* [out, retval] */ VARIANT_BOOL* retVal );
public bool FindPattern( string Pattern, int Flags, ref TextRanges Tags );
public function FindPattern( Pattern : String, Flags : int, Tags : TextRanges ) : Boolean
Parameters
- Pattern
- Required. The text to find.
- Flags
- Optional. A vsFindPatternSyntax constant indicating the type of pattern to find.
- Tags
- Optional. If the matched pattern is a regular expression containing tagged subexpressions, then Tags argument contains a collection of TextRange Objects, one for each tagged sub-expression.
Return Value
True if the pattern is found, False if not.
Remarks
FindPattern searches for the given text pattern from the edit point to the end of the document. One of the flags controls whether the search starts at the beginning of the document. The pattern may be a regular or other expression. The return value indicates whether the pattern is found. If the pattern is found, the edit point is moved to the beginning of the match. Otherwise, the edit location is unchanged.
If an end point is supplied and the pattern found, then FindPattern moves the end point to the end of the found pattern.
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.
Example
Sub FindPatternExample()
' Before running this example, open a text document.
Dim objSel As TextSelection = DTE.ActiveDocument.Selection
' Advance to the next Visual Basic .NET function beginning or end by
' searching for "Sub" with white space before and after it.
If objSel.FindPattern(":WhSub:Wh", vsFindOptions.vsFindOptionsRegularExpression) Then
' Select the entire line.
objSel.SelectLine()
End If
End Sub
See Also
Applies To: TextSelection Object