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
必要項。要尋找的文字。
- vsFindOptionsValue
型別:System.Int32
選擇項。vsFindOptions 常數,表示要執行的搜尋類型。vsFindOptionsMatchInHiddenText 常數值並不適用這個方法,因為 FindPattern 會搜尋包含隱藏文字的所有文字。
- EndPoint
型別:EnvDTE.EditPoint%
選擇項。EditPoint 物件,表示要移動到符合模式比對的結尾點。
- 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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。