TextSelection.FindPattern 方法

更新:2007 年 11 月

在活动点到文档结尾的范围内搜索给定模式。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Function FindPattern ( _
    Pattern As String, _
    vsFindOptionsValue As Integer, _
    <OutAttribute> ByRef Tags As TextRanges _
) As Boolean
用法
Dim instance As TextSelection
Dim Pattern As String
Dim vsFindOptionsValue As Integer
Dim Tags As TextRanges
Dim returnValue As Boolean

returnValue = instance.FindPattern(Pattern, _
    vsFindOptionsValue, Tags)
bool FindPattern(
    string Pattern,
    int vsFindOptionsValue,
    out TextRanges Tags
)
bool FindPattern(
    [InAttribute] String^ Pattern, 
    [InAttribute] int vsFindOptionsValue, 
    [InAttribute] [OutAttribute] TextRanges^% Tags
)
function FindPattern(
    Pattern : String, 
    vsFindOptionsValue : int, 
    Tags : TextRanges
) : boolean

参数

  • Tags
    类型:EnvDTE.TextRanges%

    可选。如果匹配的模式是一个正则表达式并且包含带标记的子表达式,则 Tags 参数包含一组 TextRange 对象,每个带标记的子表达式对应一个对象。

返回值

类型:System.Boolean

一个布尔值,如果找到模式,则为 true,否则为 false。

备注

FindPattern 在编辑点到文档结尾的范围内搜索给定的文本模式。其中一个标志控制是否从文档开头开始搜索。模式可以是正则表达式,也可以是其他表达式。返回值指示是否找到了模式。如果找到了模式,编辑点就移动到匹配项的开始处。否则,编辑位置保持不变。

如果提供了终结点并且找到了模式,则 FindPattern 将终结点移动到找到的模式的结尾。

如果匹配的模式是一个正则表达式并且包含带标记的子表达式,则 Tags 参数返回一组 TextRange 对象,每个带标记的子表达式对应一个对象。

示例

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

   ' Advance to the next Visual Basic 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

权限

另请参见

参考

TextSelection 接口

TextSelection 成员

EnvDTE 命名空间