Replace Text Action

Declaration

<AMREPLACE TEXT="test" FIND="test" REPLACE="test" RESULTVARIABLE="text [variable name]" USERE="YES" USECASE="YES" INDEX="6" MAXMATCHES="6" TOTALMATCHESVAR="text [variable name]">

See Also

Replace Text Action-Setting Properties, Find Text Action, Get Subtext Action, Insert Text Action, Trim Text Action

Description

Finds and replaces each or every occurrence of a text pattern and places the result into a variable.  Regular expressions may be used for added power and flexibility.

Practical Usage

Used to find and replace a word or phrase inside of a larger piece of text .

Parameters

General Tab

Text

Text, Required
MARKUP: TEXT="My Name is Joe"

Specifies target text to be searched.  

Find

text,Required
MARKUP: FIND="Joe"

Specifies the text to search for.

Replace With

text,Required
MARKUP: REPLACE="Jim"

Specifies the text to replace the found text with.

Case Sensitive

Yes/No, Optional (default: No)
MARKUP: USECASE="YES"

Specifies whether the search performed should be case sensitive.  

Regular Expression

Yes/No, Optional (default: No)
MARKUP: USERE="YES"

Specifies whether the FIND parameter is a regular expression. If the option is no, the Find parameter contains literal text, if the option is yes, the find parameter contains a regular expression.

Populate Variable with first result

Text [variable name], Required
MARKUP: RESULTVARIABLE="varname"

Specifies the variable to receive the new text.

Advanced Tab

Starting at the following instance

Number, Optional (default: 1)
MARKUP: INDEX="5"

Specifies target text to be searched.  

Maximum Replacements

Text [variable name], Optional (default:0)
MARKUP: MAXMATCHES="6"

Specifies the maximum number of replacements that should be made. If 0(default) is specified, all instances of the found text will be replaced.

Total Replacement Count into variable

Text [variable name], Required
MARKUP: TOTALMATCHESVAR="varname"

Specifies the variable to receive the total number of replacements that were made.

Notes

Using Variables

All variables must be created before they can be used. This is done using the Create Variable <AMVARIABLE> action. Once created, variables can be set using the Set Variable <AMSET> action, or by certain actions that support populating variables. To get data out of the variables, in any action parameter, simply surround the variable name with percentage % signs (e.g. %varname%). Remember not to use percentage signs when specifying the name of a variable to populate, percentage signs are only needed to get data out.

Custom Description

This action includes the Description tab for entering a custom step description.

More on setting custom step description

Standard Error Handling Options

This action also includes the standard Error Causes and On Error failure handling options/tabs.

More on Error Handling Options

Variables and Expressions

All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by pressing F2.

More on variables
More on expressions

More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

<AMVARIABLE NAME="sourcedata">AutoMate Version 5.5 Adds Power, Speed, Flexibility and Intelligence.</AMVARIABLE>
<AMVARIABLE NAME="newdata"></AMVARIABLE>
<AMREPLACE TEXT="%sourcedata%" FIND="Speed" REPLACE="Good Looks" RESULTVARIABLE="newdata">
<AMMESSAGEBOX>BEFORE: %sourcedata%

AFTER: %newdata%</AMMESSAGEBOX>