Find.FindReplace Method

Performs a Find or Replacement operation based on the arguments to the method, without affecting the options set for the Find.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

vsFindResult FindReplace(
	vsFindAction Action,
	string FindWhat,
	int vsFindOptionsValue,
	string ReplaceWith,
	vsFindTarget Target,
	string SearchPath,
	string FilesOfType,
	vsFindResultsLocation ResultsLocation


Type: EnvDTE.vsFindAction
Required. A vsFindAction constant that indicates the search action to take.
Type: System.String
Optional. The pattern to search for. The default is "".
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 of these is supplied, then FindWhat is matched literally.
vsFindOptionsValue defaults to all flags turned off.
Type: System.String
Optional. A string with which to replace the matched text when Action is set to vsFindActionReplace or vsFindActionReplaceAll. Default value is "".
Type: EnvDTE.vsFindTarget
Optional. A vsFindTarget constant that indicates the target for the search operation, such as the current document or find-in-files.
Type: System.String
Optional. A semicolon-separated list of directories and file names to search. The default value is "".
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 "", meaning all files are searched.
Type: EnvDTE.vsFindResultsLocation
Optional. A vsFindResultsLocation constant. There are two possible results 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.

Return Value

Type: EnvDTE.vsFindResult
A vsFindResult constant.

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
   objFind.FindReplace(vsFindAction.vsFindActionReplaceAll, "test", vsFindOptions.vsFindOptionsMatchWholeWord, "NEW THING", vsFindTarget.vsFindTargetOpenDocuments, , , vsFindResultsLocation.vsFindResultsNone)
End Sub

Community Additions