How to replace a word with a different set of words

Help with writing and playing macros

How to replace a word with a different set of words

Postby vortex » Sat Apr 25, 2009 7:16 pm

Can this be done?
----------------
test example text looks like this
test whatever text is this
test3 Blahh
test text looks this
test2 Blah
----------------
"test" should be replaced by "one" and "two" so that the final text looks like:
"test2" should be replaced by "uno" and "dos" and "treis"
"test3" should be replaced by "xx"

----------------
one example text looks like this
two whatever text is this
xx Blahh
one text looks this
uno Blah
----------------

this should be done from the beginning to the end of the textfile 1x. It could appear that a "testx" may not appear in the file. It should not stop at this point.


Thanx alot
vortex
Newbie
 
Posts: 1
Joined: Sat Apr 25, 2009 7:09 pm

Re: How to replace a word with a different set of words

Postby Mofi » Mon Apr 27, 2009 3:03 am

Looks similar to Replace line after line, is this somehow possible and therefore I suggest to adapt the macro posted there to your word replacing need. How exactly the macro will look depends on the second file with the word sets. For example if the second file with the words to search for and replace with looks like this:

Code: Select all
!test
one
two
!test2
uno
dos
treis
!test3
xx

the following macro would do the job. The macro property Continue if search string not found must be checked for this macro.

InsertMode
ColumnModeOff
HexOff
UnixReOff
SelectAll
Clipboard 9
Copy
NextWindow
Top
Paste
IfColNumGt 1
"
#
"
Else
"#
"
EndIf
Top
Loop 0
IfCharIs "#"
ExitLoop
EndIf
IfCharIs "!"
Key RIGHT ARROW
SelectWord
Cut
DeleteLine
EndIf
SelectWord
Find MatchCase MatchWord "^c"
Replace "^s"
IfNotFound
Top
StartSelect
Find RegExp Select "%[!#]"
Key HOME
Delete
EndSelect
Else
Top
DeleteLine
EndIf
EndLoop
DeleteLine
ClearClipboard
Clipboard 0
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4042
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros