Topic: Line-By-Line Search and Replace (1 of 3), Read 28 times
Conf: VEDIT Macro Language Support
From: Dale Cook
Date: Saturday, December 11, 2004 07:53 PM

I'm having trouble getting Search and Replace to do what I need. I need to go through a file line-by-line, and in each line I need to find every third instance of "XXXXX" and replace that with "YYY" (these are dummy strings for illustration, since putting the actual HTML code I'm finding and replacing might cause this message to display improperly). Then I need to move to the next line and start again with every third instance there. What I've tried so far either fails completely, or replaces every third instance in the file, rather than every third instance in each line. Any suggestions?

 


Topic: Re: Line-By-Line Search and Replace (2 of 3), Read 27 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Sunday, December 12, 2004 03:33 AM

Dale:

On Sat, 11 Dec 2004 19:53:00 -0500, you wrote:

>I'm having trouble getting Search and Replace to do what I need.
>I need to go through a file line-by-line, and in each line I need
>to find every third instance of "XXXXX" and replace that with
>"YYY" [...]


Try it with the following:


Begin_Of_File

while (! At_EOF) {
Search_Block("XXXXX", BoL_Pos, EoL_Pos, NOERR+COUNT,3)
if (! Error_Match) {
Replace("XXXXX", "YYY")
}
Line(1, NOERR)
}


Christian

 


Topic: Re: Line-By-Line Search and Replace (3 of 3), Read 28 times
Conf: VEDIT Macro Language Support
From: Dale Cook
Date: Sunday, December 12, 2004 05:53 AM

Christian -

Thanks - that nailed it. I've been using Search and Replace for years, don't know how I overlooked Search_Block but I did.

BTW, for anyone wondering, I'm converting the OCRd scans of the index pages from a large book into an HTML index. The purpose of this function is to force the first three page links to display on the same line as the indexed subject subdivision, but allow line breaks after that point if the subject subdivision indexes to more than three pages. This presents a more readable display at any monitor resolution, a concern since many in the target audience are still running old machines with 640 x 480 screens.

- Dale