This documentation is archived and is not being maintained.

FindReplace Method

Visual Studio .NET 2003

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

[Visual Basic .NET]
Public Function FindReplace( _
   ByVal Action As vsFindAction, _
   ByVal FindWhat As String, _
   Optional ByVal Options As Integer = 0, _
   Optional ByVal ReplaceWith As String = "", _
   Optional ByVal Target As vsFindTarget = vsFindTargetCurrentDocument, _
   Optional ByVal SearchPath As String = "", _
   Optional ByVal FilesOfType As String = "", _
   Optional ByVal ResultsLocation As vsFindResultsLocation = vsFindResults1 _
) As vsFindResult
[Visual Basic 6]
Function FindReplace( _
   ByVal Action As vsFindAction, _
   ByVal FindWhat As String, _
   Optional ByVal Options As Long = 0, _
   Optional ByVal ReplaceWith As String = "", _
   Optional ByVal Target As vsFindTarget = vsFindTargetCurrentDocument, _
   Optional ByVal SearchPath As String = "", _
   Optional ByVal FilesOfType As String = "", _
   Optional ByVal ResultsLocation As vsFindResultsLocation = vsFindResults1 _
) As vsFindResult
[C++]
HRESULT __stdcall FindReplace(
   vsFindAction Action,
   BSTR FindWhat,
   long Options,
   BSTR ReplaceWith,
   vsFindTarget Target,
   BSTR SearchPath,
   BSTR FilesOfType,
   vsFindResultsLocation ResultsLocation,
   /* [out, retval] */ vsFindResult* retVal
);
[C#]
public vsFindResult FindReplace(
   vsFindAction Action,
   string FindWhat,
   int Options,
   string ReplaceWith,
   vsFindTarget Target,
   string SearchPath,
   string FilesOfType,
   vsFindResultsLocation ResultsLocation
);
[JScript .NET]
public function FindReplace(
   Action : vsFindAction,
   FindWhat : String,
   Options : 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 "".
Options
Optional. A bit field indicating several aspects of the search to perform.
  • For matching, you can supply vsFindMatchCase, 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.

Options 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 filenames 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

Returns a vsFindResult constant.

Example

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

See Also

Action Property | Execute Method | FindWhat Property | ReplaceWith Property | ResultsLocation Property

Applies To: Find Object

Show: