共用方式為


EditPoint.FindPattern 方法

在選取的文字中尋找指定的比對模式。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Function FindPattern ( _
    Pattern As String, _
    vsFindOptionsValue As Integer, _
    <OutAttribute> ByRef EndPoint As EditPoint, _
    <OutAttribute> ByRef Tags As TextRanges _
) As Boolean
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
)
abstract FindPattern : 
        Pattern:string * 
        vsFindOptionsValue:int * 
        EndPoint:EditPoint byref * 
        Tags:TextRanges byref -> bool 
function FindPattern(
    Pattern : String, 
    vsFindOptionsValue : int, 
    EndPoint : EditPoint, 
    Tags : TextRanges
) : boolean

參數

  • Pattern
    型別:System.String
    必要項。要尋找的文字。
  • Tags
    型別:EnvDTE.TextRanges%
    選擇項。如果符合的模式比對是規則運算式 (Regular Expression) 並且含有標記子運算式 (Subexpression),則 Tags 引數會包含 TextRange 物件的集合,每個物件都會對應到一個標記子運算式。

傳回值

型別:System.Boolean
如果找到模式比對,則為 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

.NET Framework 安全性

請參閱

參考

EditPoint 介面

EnvDTE 命名空間