Finding/Replacing multiple strings in one document?

Find, replace, find in files, replace in files, regular expressions

Finding/Replacing multiple strings in one document?

Postby sonofsamx » Tue Nov 22, 2005 3:59 pm

I have a text file where I need to replace several strings with new strings. After reading several threads in this and in the macros section, I have gotten this far, where I can find and replace ONE string successfully:


InsertMode
ColumnModeOff
HexOff
UnixReOff
Bottom
IfColNum 1
Else
"
"
EndIf
Top
Loop
Find "' '"
IfFound
"'SPACE'"
IfEof
ExitLoop
EndIf
EndLoop


My problem is that I don't understand how to make it repeatedly loop to the top of the file and search for the next item I need replaced until it's searched for them all, and then stop. I will have to make this macro find/replace 10 or so separate strings of text.

Here are a few examples of what I will need to find/replace, if it helps:
Find "' '"
IfFound
"'SPACE'"

Find "';'"
IfFound
"'SEMICOLON'"

Find "','"
IfFound
"'COMMA'"

Thanks in advance for any help you can provide!
-sonofsamx
User avatar
sonofsamx
Newbie
 
Posts: 2
Joined: Tue Nov 22, 2005 12:00 am

Re: Finding/Replacing multiple strings in one document?

Postby Mofi » Tue Nov 22, 2005 4:46 pm

In your macro an additional EndIf is missing. You have IfFound and IfEof, but only 1 EndIf. If all replaces are as easy as this one than use

Find "search text1"
Replace All "replace text 1"
Find "search text2"
Replace All "replace text 2"
Find "search text3"
Replace All "replace text 3"

and throw away the IfFound and IfEof section. This is much faster than a loop. Don't forget to activate macro property Continue if a Find with Replace not found.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Finding/Replacing multiple strings in one document?

Postby sonofsamx » Tue Nov 22, 2005 4:59 pm

Thank you so much, Mofi. I'm glad it was that easy to do and I appreciate your help! It works great now!

(I had tried to use Replace All but had it as one word ReplaceAll and it broke - now I know why it wouldn't work! Dumb me... :))

-sonofsamx
User avatar
sonofsamx
Newbie
 
Posts: 2
Joined: Tue Nov 22, 2005 12:00 am


Return to Find/Replace/Regular Expressions