Find2::FindReplace Method (vsFindAction, String^, Int32, String^, vsFindTarget, String^, String^, vsFindResultsLocation)
Performs a Find or Replace operation based on the arguments to the method, without affecting the options set for the Find object.
Assembly: EnvDTE80 (in EnvDTE80.dll)
vsFindResult FindReplace( vsFindAction Action, String^ FindWhat, int vsFindOptionsValue = 0, String^ ReplaceWith = "", vsFindTarget Target = vsFindTarget::vsFindTargetCurrentDocument, String^ SearchPath = "", String^ FilesOfType = "", vsFindResultsLocation ResultsLocation = vsFindResultsLocation::vsFindResults1 )
Parameters
- Action
-
Type:
EnvDTE::vsFindAction
Required. A vsFindAction constant that indicates the search action to take.
- FindWhat
-
Type:
System::String^
Optional. The pattern to search for. The default is "".
- vsFindOptionsValue
-
Type:
System::Int32
Optional. A bit field indicating several aspects of the search to perform.
For matching, you can supply vsFindOptionsMatchCase, vsFindOptionsMatchWholeWord, or vsFindOptionsMatchInHiddenText.
Flags that can be turned on for files, project, and solution targets are vsFindOptionsSearchSubfolders and vsFindOptionsKeepModifiedDocumentsOpen.
Flags for the FindWhat property syntax are vsFindOptionsRegularExpression and vsFindOptionsWildcards. If neither is supplied, then FindWhat is matched literally.
vsFindOptionsValue defaults to all flags turned off.
- ReplaceWith
-
Type:
System::String^
Optional. A string with which to replace the matched text when Action is set to vsFindActionReplace or vsFindActionReplaceAll. Default value is "".
- Target
-
Type:
EnvDTE::vsFindTarget
Optional. A vsFindTarget constant that indicates the target for the search operation, such as the current document or find-in-files.
- SearchPath
-
Type:
System::String^
Optional. A semicolon-separated list of directories and file names to search. The default value is "".
- FilesOfType
-
Type:
System::String^
Optional. A semicolon-separated list of file types to include in the search. Other file types encountered in the specified targets are ignored. The default value is "", which means that all files are searched.
- ResultsLocation
-
Type:
EnvDTE::vsFindResultsLocation
Optional. A vsFindResultsLocation constant. There are two possible result lists where Find results can display. You can perform two searches without overwriting the results of the first search. Using ResultsLocation, you can determine the result list in which to place the Find results.
Sub FindReplaceExample() Dim objTextDoc As TextDocument Dim objEditPt As EditPoint Dim iCtr As Integer Dim objFind As Find ' 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 objFind = objTextDoc.DTE.Find ' Insert ten lines of text. For iCtr = 1 To 10 objEditPt.Insert("This is a test." & Chr(13)) Next iCtr objEditPt.StartOfDocument() objFind.FindReplace(vsFindAction.vsFindActionReplaceAll, "test", vsFindOptions.vsFindOptionsMatchWholeWord, "NEW THING", vsFindTarget.vsFindTargetOpenDocuments, , , vsFindResultsLocation.vsFindResultsNone) End Sub