Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] General Discussion
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-01-2004, 04:34 AM
Dimitri Dimitri is online now
Registered User
 
Join Date: 08-27-2004
Posts: 6
Question Replace in file: How to replace a single string by multiple lines?

[Thanks for this excellent tool, it saves many many hours and above all, is fun to use!]

Is there a way I can replace a single identifier in a file by multiple lines? It works almost correct when "Treat all characters as literals" is off (the default), but then it performs regular expressions which for example results in "(" and ")" not being copied into the dest file.
And when I turn "Treat all characters as literals" on I get the step error:
"Number of search and replacement strings must match."
(which goes away when I only replace with a single line, instead of multiple lines).

How can I replace a single string by multiple lines and not perform any reg-exing at the same time?

P.S.:
As "replace with" I use a file's content (using vbld_FSO.OpenTextFile's ReadAll), this file is edited by doc maintainers so I would _preferably_ like to keep it clean from any escape-sequences (if that would solve the "(" disappearing in some way).

[Edit: Using VBPro5.5 with WinXP Home SP1]
Reply With Quote
  #2  
Old 09-01-2004, 06:53 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Using the Replace in File action, you would need to use regular expressions to find or replace strings containing newlines (and escape out any special regex characters). For this special case, you could roll your own using the FileSystemObject (see attached).
Attached Files
File Type: bld repl_multline.bld (2.2 KB, 1596 views)
Reply With Quote
  #3  
Old 09-01-2004, 09:42 AM
Dimitri Dimitri is online now
Registered User
 
Join Date: 08-27-2004
Posts: 6
Thanks a lot, it's working fine!
Is there a problem with interpreting a single-line Find field (while "no regex" is enabled) as the user wanting to replace that with what's literally in the Replace field? It seems intuitive to me and took me some time to figure out what VBPro was telling me (that the number of lines has to be equal).
Reply With Quote
  #4  
Old 09-01-2004, 10:18 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
By design, the current implementation allows replacing multiple literal values in a single Replace in File action, which precludes multi-line matches or replacement values. From the help:

For literal text, this can be a single search and replace value, with the 'no regular expressions' field checked. To search and replace multiple literal values, enter each value on a separate line (the number of search and replace lines must match). For instance, to change all occurrences of 'fox' with 'cat' and 'dog' with 'beagle', the find expression

fox
dog

and replace expression

cat
beagle

could be used.
Reply With Quote
  #5  
Old 09-01-2004, 11:16 AM
Dimitri Dimitri is online now
Registered User
 
Join Date: 08-27-2004
Posts: 6
Yes, I understand (and had seen the multiline usage in one of the samples). However what I mean is, instead of treating a single source line (and 1 only!) with multiple dest lines as an error, couldn't it be interpreted as meaning 'replace this one thing with whatever is in dest'? Or provide this functionality in some other way (since it would be somewhat confusing behaviour otherwise), perhaps on a different new tab-panel in Replace in File properties?

Replace in File is very powerful, but I think it would be helpful if it could also do very basic (?) stuff such as this (without having to do regex 'trickery', or a script (thanks again ), the first need I at least had for Replace in File was replacing a single identifier with a paragraph in a readme.txt file (multiple times).
Reply With Quote
  #6  
Old 09-01-2004, 11:31 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Yes, I suppose it could handle this special case to support replacing a single line literal with multiple lines. We'll add it to the list.
Reply With Quote
  #7  
Old 09-02-2004, 05:52 AM
Dimitri Dimitri is online now
Registered User
 
Join Date: 08-27-2004
Posts: 6
Thanks for considering it. I now think such behaviour would even make sense (as opposed to being a hidden feature) : Replace in file can already replace a single identifier by multiple lines when "Treat all characters as literals" is off. The only difference here is the checkbox is checked.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 06:59 PM.


Copyright © 1999-2023 Kinook Software, Inc.