From: mcnews on 19 Apr 2010 10:27 how would you do a search and replace like this? <!-- start marker 1 --> bunch o text <!-- end marker 1 --> let's say you want to replace what ever is between the start and end markers with text from an external file. would just like some smart tips how to do this with VB. tia, mcnewsxp
From: dpb on 19 Apr 2010 10:38 mcnews wrote: > how would you do a search and replace like this? > > <!-- start marker 1 --> > > bunch o text > > <!-- end marker 1 --> > > let's say you want to replace what ever is between the start and end > markers with text from an external file. > would just like some smart tips how to do this with VB. mid$() comes to mind... Simplest would be if can be held in memory to read target into string variable, find start/end and replace. Fastest if sizes are considerable could be the memmove() tricks (easily found by google here or on web as it's been discussed ad nauseum)... --
From: duke on 19 Apr 2010 11:22 On Apr 19, 8:27 am, mcnews <mcour...(a)mindspring.com> wrote: > how would you do a search and replace like this? > > <!-- start marker 1 --> > > bunch o text > > <!-- end marker 1 --> > > let's say you want to replace what ever is between the start and end > markers with text from an external file. > would just like some smart tips how to do this with VB. > > tia, > mcnewsxp Your question did not describe the source of the text, so I would limit my suggestion just to the search & replace which is covered by the replace statement: text1.text = replace(text1.text,"search text", "replace text",start position, occurrence, compare type) Finding the start position (start / end marker) can normally be determined with the use of the InStr statement or omitting the start position searches the entire value of text1.text Duke
From: duke on 19 Apr 2010 11:25 On Apr 19, 8:27 am, mcnews <mcour...(a)mindspring.com> wrote: > how would you do a search and replace like this? > > <!-- start marker 1 --> > > bunch o text > > <!-- end marker 1 --> > > let's say you want to replace what ever is between the start and end > markers with text from an external file. > would just like some smart tips how to do this with VB. > > tia, > mcnewsxp My apologies.... I reread your question, you did say the text is coming from an external file. Anyways, you could apply the replace statement to the buffer area of the file then write the contents back out to disk. Duke
From: mcnews on 19 Apr 2010 12:22
On Apr 19, 11:25 am, duke <nosp...(a)3web.net> wrote: > On Apr 19, 8:27 am, mcnews <mcour...(a)mindspring.com> wrote: > > > how would you do a search and replace like this? > > > <!-- start marker 1 --> > > > bunch o text > > > <!-- end marker 1 --> > > > let's say you want to replace what ever is between the start and end > > markers with text from an external file. > > would just like some smart tips how to do this with VB. > > > tia, > > mcnewsxp > > My apologies.... I reread your question, you did say the text is > coming from an external file. > > Anyways, you could apply the replace statement to the buffer area of > the file then write the contents back out to disk. > > Duke that is pretty much what i am doing now except that i am just looking for the first marker. what would be the best way to grab the text between to start and end markers? |