ReplaceText Method
Home Page (Objects) | Overview | FAQ | Reference
Applies to: TextDocument****object, TextSelection object
Replaces all instances of a string or regular expression with another string or regular expression.
Syntax
object**.ReplaceText(CurrString,RepString**[**,**flags] )
Parameters
object
An expression that evaluates to a TextDocument object or a TextSelection object.
CurrString
The String you want to replace.
RepString
The replacement String.
flags
(Optional) A string constant of type DsTextSearchOptions that determines how to conduct the search. To perform complex searches, you can combine values. The values you can use singly or in combination are:
dsMatchForward Causes a forward search from the beginning of the document. This is the default.
dsMatchBackward Causes a backward search from the end of the document.
dsMatchWord Requires that whole words match.
dsMatchCase Requires a case-sensitive match.
dsMatchRegExp Requires a match with Developer Studio regular expressions.
dsMatchNoRegExp Does not require a match with Developer Studio regular expressions. This is the default.
dsMatchRegExpB Requires a match with BRIEF® regular expressions.
dsMatchRegExpE Requires a match with Epsilon™ regular expressions.
dsMatchRegExpCur Requires a match using the current regular expression setting.
Return Values
The ReplaceText method returns one of the following values:
True If one or more replacements occur.
False If no replacements occur.
Remarks
The following table summarizes the results of using the ReplaceText method with the objects in the Applies To list:
Object | Results |
TextDocument | Replaces all instances of the specified text string in the entire document. |
TextSelection | Replaces all instances of the specified text string in the current selection. |
You can combine string constants in the flags parameter by using the or or + operators. For example, to conduct a case-sensitive forward search, you could specify dsMatchForward or dsMatchCase or dsMatchForward + dsMatchCase. However, you can use only one of the regular expression values at a time. For example, you cannot combine dsMatchRegExpCur with dsMatchRegExpE.
Example
In the current selection, the following example replaces all occurrences of "LPVOID" with "void *" by using tagged regular expressions:
Sub ReplaceLPVOID
ActiveDocument.Selection.ReplaceText "LPVOID", "void *", dsMatchCase + dsMatchWord
End Sub