Topic: Re: VEDIT search and replace question (1 of 11), Read 124 times
Conf: Search and Replace
From: Christian Ziemski
Date: Wednesday, May 26, 2004 08:52 AM

Bill:

On Thu, 13 May 2004 02:11:17 -0400, you wrote via personal mail:

>Christian,
>
>I'm trying to make a small change. Could you help?
>
>I think it's a simple one.
>
>In an HTML file, I want to delete ONLY THE FIRST TABLE ROW that contains a
>string. Then move on to the next file, not changing the other occurrences in
>the first file.
>
>I'm trying the following, but it seems not to be editing anything.
>
>I assume my string commands are correct, but I don't know how to tell it to
>do just one change. I'm trying to throw in an extra EOF, but that's all
>wrong.
>
>
>Could you help (once again)?
>
>---
>
>// 1.) Delete only the first HTML table row containing "<b>2003</b>"
>
>Begin_Of_File
>repeat (ALL) { // endless loop
> Block_Begin(CLEAR) // reset block
>markers
> Search("|X", NOERR+CONFIRM+ERRBREAK) // search for a
>complete string until end, marking a row
> Search_Block("<b>2003</b>", BB, BE, BEGIN+NOERR) // search within
>that string for the "#N/A"
> if (! EM) { // if "#N/A" found:
>delete the block
> Del_Block(Block_Begin, Block_End)
> } else { // else: set cursor
>at EOF
> EOF
> }
> EOF //
>go to end of file; no more changes...
>}


####
## Since this discussion may be of interest for others please let us
## continue here at WebBoard and not via personal mail.
####

Your mistake in the above code is the following:

You are jumping to EOF immediately after the first table row, if there
is no "<b>2003</b>" in it.
And that could happen really early. Too early most times.

So I would suggest:


Begin_Of_File
repeat (ALL) { // endless loop
Block_Begin(CLEAR) // reset markers
Search("|X", NOERR+CONFIRM+ERRBREAK) // search for a
// complete string
// until end,
// marking a row
Search_Block("<b>2003</b>", BB, BE, BEGIN+NOERR) // search within
// string for ...
if (! EM) { // if found:
// delete the block
Del_Block(Block_Begin, Block_End) // and
break // exit loop
} else { // if not found:
Goto_Pos(Block_End) // continue at BE
}
}



Christian

 


Topic: Re: VEDIT search and replace question (2 of 11), Read 114 times
Conf: Search and Replace
From: Bill Dedman
Date: Thursday, May 13, 2004 05:41 PM

Thanks so much, Christian. That worked great.

Bill

 


Topic: Re: VEDIT search and replace question (3 of 11), Read 108 times
Conf: Search and Replace
From: Bill Dedman
Date: Tuesday, May 25, 2004 11:38 AM

Another variation:

In the macro, how would I find a string and then insert it elsewhere in the document?

Such as, I'd like to look for the text between "XXX" and "YYY." These markers appear only once in the document, in the middle. Capture that text between those markers.

Then, higher in the document, make that text the title of the HTML document, by inserting it between "title>" and "</title"

Thanks again for your help.

Bill

 


Topic: Re: VEDIT search and replace question (4 of 11), Read 115 times
Conf: Search and Replace
From: Christian Ziemski
Date: Thursday, May 27, 2004 03:30 PM

On Tue, 25 May 2004 11:38:00 -0400, Bill Dedman wrote:

>In the macro, how would I find a string and then insert it elsewhere in the
>document?
>
>Such as, I'd like to look for the text between "XXX" and "YYY." These markers
>appear only once in the document, in the middle. Capture that text between
>those markers.
>
>Then, higher in the document, make that text the title of the HTML document, by
>inserting it between "title>" and "</title"


The Automatic-Webboard-Answering-Machine would say:


You already described it in "pseudo code"!
An implementation in VDM could be like this:


Begin_Of_File

Search("XXX|MYYY", NOERR) // search source
// (any text delimited by XXX and YYY)

if ( ! Error_Match ) { // if no error (XXX...YYY pair found)
Char(3) // move forward; past XXX
Block_Begin(Cur_Pos) // remember this position (mark block)
Search("YYY") // move to YYY (beginning of)
Block_End(Cur_Pos) // set end of block here

Reg_Copy_Block(103, Block_Begin, Block_End) // save that block to a register
Block_Begin(CLEAR) // clear block markers

Begin_Of_File // jump to begin of file
Search("title></title", NOERR) // search target
if ( ! Error_Match ) { // if found
Char(6) // move inside target (past "title>")
Reg_Ins(103) // insert saved text here
}
}




You can see: It's often straight-forward to do a macro in VEDIT.
That's exactly one of the powers of VEDIT!


Regards

TAWAM ;-)

 


Topic: Re: VEDIT search and replace question (5 of 11), Read 108 times
Conf: Search and Replace
From: Ted Green
Date: Tuesday, May 25, 2004 02:10 PM

At 11:38 AM 5/25/2004, you wrote:
>In the macro, how would I find a string and then insert it elsewhere in the document?

I see that Christian has answered.

You should also review "Setting Block Markers by Searching" on pages 91-92 of the VEDIT 6.0 Macro Language Reference Manual. (Printed or .PDF)

Ted.

 


Topic: Re: VEDIT search and replace question (6 of 11), Read 108 times
Conf: Search and Replace
From: Bill Dedman
Date: Wednesday, May 26, 2004 03:06 AM

Thanks again!

But simple, no.

 


Topic: Re: VEDIT search and replace question (7 of 11), Read 107 times
Conf: Search and Replace
From: Christian Ziemski
Date: Wednesday, May 26, 2004 09:56 AM

On 5/26/2004 3:06:10 AM, Bill Dedman wrote:

>But simple, no.

No?
O.k. If we can explain something, feel free to ask.

Christian

 


Topic: Re: VEDIT search and replace question (8 of 11), Read 108 times
Conf: Search and Replace
From: Ian Binnie
Date: Wednesday, May 26, 2004 11:19 PM

On 5/26/2004 9:56:12 AM, Christian Ziemski wrote:
>On 5/26/2004 3:06:10 AM, Bill Dedman
>wrote:
>
>>But simple, no.
>
>No?
>O.k. If we can explain something, feel
>free to ask.
>
>Christian

Christian,

It may help if you used full commands in your examples, rather than abbreviations.

I write quite a few macros, and I had to look up "EM".

 


Topic: Re: VEDIT search and replace question (9 of 11), Read 112 times
Conf: Search and Replace
From: Christian Ziemski
Date: Thursday, May 27, 2004 03:33 PM

On 5/26/2004 11:19:56 PM, Ian Binnie wrote:
>
>It may help if you used full commands in
>your examples, rather than abbreviations.

O.k., that's correct.
Most times I'm using the long names. Only some are short.

But now I edited my above message to have the macro coding more informative.

Christian

 


Topic: Re: VEDIT search and replace question (10 of 11), Read 89 times
Conf: Search and Replace
From: Gary Darsey
Date: Thursday, August 12, 2004 03:10 PM

In working through this topic (for my own education), I found that no good information on Error_Match appears in the online help (6.12.1) for the various Search() commands. It appears in my older VEDIT 5.0 printed manual and in the PDF manual under "Return:". Could this information be added to the online help? A search on Error_Match or EM with the online help brings one to a terse description in the Interval Values section with no link to a more full description.

Thanks!

-Gary

 


Topic: Re: VEDIT search and replace question (11 of 11), Read 89 times
Conf: Search and Replace
From: Christian Ziemski
Date: Thursday, August 12, 2004 04:10 PM

On Thu, 12 Aug 2004 15:10:00 -0400, Gary Darsey wrote:

>[...] I found that no good information on Error_Match appears
>in the online help (6.12.1) for the various Search() commands.
>It appears in my older VEDIT 5.0 printed manual and in the
>PDF manual under "Return:".

In the PDF there is a longer description in chapter 4 (page 152),
together with Error_Flag and Error_OS.

The online help only lists it in the Match() command.

Within the description of the Search() commands it's missing:

"Return: Search( ) and Replace( ) return the number of
occurrences found, 0 if none.

Chars_Matched is set to the number of chars matched by 'ss'.
Error_Flag is set if the search is not successful. "


I agree that it would be helpful to have more info about EM in the
online help.


Christian