FindReplace Method
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

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)

'Declaration
Function FindReplace ( _
	<InAttribute> Action As vsFindAction, _
	<InAttribute> FindWhat As String, _
	<InAttribute> <OptionalAttribute> Optional vsFindOptionsValue As Integer = 0, _
	<InAttribute> <OptionalAttribute> Optional ReplaceWith As String = "", _
	<InAttribute> <OptionalAttribute> Optional Target As vsFindTarget = vsFindTarget.vsFindTargetCurrentDocument, _
	<InAttribute> <OptionalAttribute> Optional SearchPath As String = "", _
	<InAttribute> <OptionalAttribute> Optional FilesOfType As String = "", _
	<InAttribute> <OptionalAttribute> Optional ResultsLocation As vsFindResultsLocation = vsFindResultsLocation.vsFindResults1 _
) As vsFindResult
'Usage
Dim instance As Find
Dim Action As vsFindAction
Dim FindWhat As String
Dim vsFindOptionsValue As Integer
Dim ReplaceWith As String
Dim Target As vsFindTarget
Dim SearchPath As String
Dim FilesOfType As String
Dim ResultsLocation As vsFindResultsLocation
Dim returnValue As vsFindResult

returnValue = instance.FindReplace(Action, FindWhat, vsFindOptionsValue, ReplaceWith, Target, SearchPath, FilesOfType, ResultsLocation)
vsFindResult FindReplace (
	/** @attribute InAttribute() */ vsFindAction Action, 
	/** @attribute InAttribute() */ String FindWhat, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int vsFindOptionsValue, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String ReplaceWith, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ vsFindTarget Target, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String SearchPath, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String FilesOfType, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ vsFindResultsLocation ResultsLocation
)
function FindReplace (
	Action : vsFindAction, 
	FindWhat : String, 
	vsFindOptionsValue : int, 
	ReplaceWith : String, 
	Target : vsFindTarget, 
	SearchPath : String, 
	FilesOfType : String, 
	ResultsLocation : vsFindResultsLocation
) : vsFindResult

Parameters

Action

Required. A vsFindAction constant that indicates the search action to take.

FindWhat

Optional. The pattern to search for. The default is "".

vsFindOptionsValue

Optional. A bit field indicating several aspects of the search to perform.

vsFindOptionsValue defaults to all flags turned off.

ReplaceWith

Optional. A string with which to replace the matched text when Action is set to vsFindActionReplace or vsFindActionReplaceAll. Default value is "".

Target

Optional. A vsFindTarget constant that indicates the target for the search operation, such as the current document or find-in-files.

SearchPath

Optional. A semicolon-separated list of directories and file names to search. The default value is "".

FilesOfType

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.

ResultsLocation

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

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