Jump to content
Macro Express Forums

Find And Replace Text Macro?


Gerry Peters

Recommended Posts

I would like to open a text file in wordpad (Word or notepad), trigger a macro to search for every occurance of 3 and rename it to three. I would want to expand it to essentially search for every occurance of a number and spell it out. If it finds 31, it renames that to thirty one. I realize I'd probably have to manually create each renamed number occurance, which is fine. Of course if it would be easier to accomplish this by directly working othe file that's fine too.

 

Can Macro Express do this?

Link to comment
Share on other sites

Something like this may work:

// Read content of file into variable T1
Variable Set String %T1% from File: "test.txt"

Replace "99" with "ninety nine" in %T1%
Replace "98" with "ninety eight" in %T1%
Replace "97" with "ninety seven" in %T1%
//                          .
//                          .
Replace "32" with "thirty two" in %T1%
Replace "31" with "thirty one" in %T1%
Replace "30" with "thirty" in %T1%
Replace "29" with "twenty nine" in %T1%
Replace "28" with "twenty eight" in %T1%
//                          .
//                          .
Replace "12" with "twelve" in %T1%
Replace "11" with "eleven" in %T1%
Replace "10" with "ten" in %T1%
Replace "9" with "nine" in %T1%
Replace "8" with "eight" in %T1%
Replace "7" with "seven" in %T1%
Replace "6" with "six" in %T1%
Replace "5" with "five" in %T1%
Replace "4" with "four" in %T1%
Replace "3" with "three" in %T1%
Replace "2" with "two" in %T1%
Replace "1" with "one" in %T1%

// Write contents of variable T1 to file
Variable Modify String: Save %T1% to Text File

Link to comment
Share on other sites

Thanks for the helpful response. I'm not used to the advanced macro creation methods. I tried just copying and pasting your text into Direct editor, but it doesn't look like it will work. I assume I need to go to scripting editor and use some of the commands under "variables". Ultimately will this macro work by opening a text file in wordpad and then hittng the hotkeys to start the macro? Or does it work on the closed text file?

 

If you would be so kind to walk a newbie through this, it would be greatly appreciated

Link to comment
Share on other sites

Hi,

sure; here are a few of Kevin's lines in direct edit; copy to script editor!

You are right; this does not bother opening notepad; easier.

Best, Randall

<VSETMISC:T4:Installation Path><REM2:use text file in installationPath "textanswers.txt"><TVAR2:05:04:%T4%\textanswers.txt><REM2:Do all your replaces here; this only example><TMVAR2:21:05:01:000:000:99ninety nine><REM2:....all numbers, descending, in between; there's probably a better way...><TMVAR2:21:05:01:000:000:2two><TMVAR2:21:05:01:000:000:1one><TMVAR2:17:05:00:000:000:%T4%\textanswers.txtT>
Set Variable %T4% to "Installation Path"

// use text file in installationPath "textanswers.txt"

Variable Set String %T5% from File: "textanswers.txt"

// Do all your replaces here; this only example

Replace "99" with "ninety nine" in %T5%

// ....all numbers, descending, in between; there's probably a better way...

Replace "2" with "two" in %T5%

Replace "1" with "one" in %T5%

Variable Modify String: Save %T5% to Text File

Link to comment
Share on other sites

I tried just copying and pasting your text into Direct editor, but it doesn't look like it will work. I assume I need to go to scripting editor and use some of the commands under "variables".
This macro is an example and would need to be edited for it to work.

 

Ultimately will this macro work by opening a text file in wordpad and then hittng the hotkeys to start the macro? Or does it work on the closed text file?

This macro does not involve Wordpad or Notepad. It reads the file into a variable, makes replacements in the string variable, and writes the content of the variable to a file. But, it is not complete. Note that I included in the sample macro replacements for 99, 98, 97, and then skipped to 32, 31, 30, 29, 28 and then skipped again to 12 through 1. Also, you will need to change the input file from test.txt to whatever your file is named. And you will need to change the output file to whatever you want. In my example, it does not show the name of the output file but I personally do not recommend that you use the same file for input and output. If the process fails in the middle, you may destroy your macro file.

 

I'm not used to the advanced macro creation methods.
I created this macro using the Scripting Editor.

 

If you would be so kind to walk a newbie through this, it would be greatly appreciated.
Start by reading the tutorials. You can access the tutorial from within the help file. Click Help and then Macro Express Help. Then click the [+] next to the Tutorial Topic. You can then highlight each tutorial topic one at a time.

 

If you haven't already, you should read the Quick Start Guide. Click Help and then Quick Start Guide. This explains that macros have something to activate them and the macro contains commands to perform different actions. The 'editor' and 'player' parts of the program are also described.

 

When I enter a macro in the Scripting Editor I put the cursor in the Search box and then type the first few letters of the command I want. Then I hit the ENTER key to put the command into the macro script.

 

For the sample macro I used the following macro commands:

 

Remark

Insert comments or remarks in the script.

 

Variable Set String

Read content of the text file into a variable (T1). Open the Variable Set String dialog, choose the 'Set Value from File' option and enter the filename and the variable (T1 through T99).

 

Replace "99" with "ninety nine" in %T1%

To enter this macro command you need to open the Variable Modify String dialog and choose the 'Replace Substring' option. Choose a variable, enter the appropriate information in the 'Text to Replace' and 'Replace With' fields.

 

Variable Modify String

Write content of a variable (T1) to a file. Opent the Variable Modify String command, click on the Option 2 tab, choose 'Save to Text File' and enter the filename and variable.

 

Make sure you use the same variable for all these commands. I used T1 for this example.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...