更新:2007 年 11 月
在选定文本中查找给定的匹配模式。
命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)
语法
声明
Function FindPattern ( _
    Pattern As String, _
    vsFindOptionsValue As Integer, _
    <OutAttribute> ByRef EndPoint As EditPoint, _
    <OutAttribute> ByRef Tags As TextRanges _
) As Boolean
用法
Dim instance As EditPoint
Dim Pattern As String
Dim vsFindOptionsValue As Integer
Dim EndPoint As EditPoint
Dim Tags As TextRanges
Dim returnValue As Boolean
returnValue = instance.FindPattern(Pattern, _
    vsFindOptionsValue, EndPoint, Tags)
bool FindPattern(
    string Pattern,
    int vsFindOptionsValue,
    out EditPoint EndPoint,
    out TextRanges Tags
)
bool FindPattern(
    [InAttribute] String^ Pattern, 
    [InAttribute] int vsFindOptionsValue, 
    [InAttribute] [OutAttribute] EditPoint^% EndPoint, 
    [InAttribute] [OutAttribute] TextRanges^% Tags
)
function FindPattern(
    Pattern : String, 
    vsFindOptionsValue : int, 
    EndPoint : EditPoint, 
    Tags : TextRanges
) : boolean
参数
- Pattern 
 类型:System.String- 必选。要查找的文本。 
- vsFindOptionsValue 
 类型:System.Int32- 可选。一个 vsFindOptions 常数,该常数指示要执行的搜索类型。vsFindOptionsMatchInHiddenText 常数值不适用于此方法,这是由于 FindPattern 搜索所有文本(包括隐藏文本)。 
- EndPoint 
 类型:EnvDTE.EditPoint%- 可选。一个 EditPoint 对象,该对象表示将移动到匹配模式结尾的点。 
- Tags 
 类型:EnvDTE.TextRanges%- 可选。如果匹配的模式是一个正则表达式并且包含带标记的子表达式,则 Tags 参数包含一组 TextRange 对象,每个带标记的子表达式对应一个对象。 
返回值
如果找到了匹配模式,则为 true;否则为 false。
备注
FindPattern 在编辑点到文档结尾的范围内搜索给定文本模式的所有文本(包括隐藏文本)。其中一个标志控制是否从文档开头开始搜索。模式可以是正则表达式,也可以是其他表达式。返回值指示是否找到了模式。如果找到了模式,编辑点就移动到匹配项的开始处。否则,编辑位置保持不变。
如果提供了终结点并且找到了模式,则 FindPattern 将终结点移动到找到的模式的结尾。
如果匹配的模式是一个正则表达式并且包含带标记的子表达式,则 Tags 参数返回一组 TextRange 对象,每个带标记的子表达式对应一个对象。
示例
Sub FindPatternExample()
   Dim objTextDoc As TextDocument
   Dim objEditPt As EditPoint, iCtr As Integer
        
   ' Create a new text file.
   DTE.ItemOperations.NewFile("General\Text File")
       
   ' Get a handle to the new document and create an EditPoint.
   objTextDoc = DTE.ActiveDocument.Object("TextDocument")
   objEditPt = objTextDoc.StartPoint.CreateEditPoint
        
   ' Insert ten lines of text.
   For iCtr = 1 To 10
      objeditpt.Insert("This is a test." & Chr(13))
   Next iCtr
   objEditPt.StartOfDocument()
   'Search for the word "test."
   If objeditpt.FindPattern("test") = True Then
      msgbox("Found the word.")
   End If
End Sub
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。