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 06-28-2004, 12:16 AM
pyang pyang is online now
Registered User
 
Join Date: 12-23-2003
Posts: 33
Replace in File query

Hi,

I'm trying to replace 2 strings in a text file. How do i do a wild search for both the strings?

Example:

String1=Testing 1234
String2=blahblahblah 456

Replace with
String1=Testing 0987
String2=blahblahblah 122

I've tried using:
To find
String1=[[^\n"]]*
String2=[[^\n"]]*

replace with
String1=Testing 0987
String2=blahblahblah 122

pls advice. Thank you.

rgds,
py
Reply With Quote
  #2  
Old 06-28-2004, 08:43 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
You need to use grouping for multiple replacements. See the attached file, the Replace in File help topic, and also the Misc.bld sample for details.
Attached Files
File Type: bld replace_two.bld (1.1 KB, 1424 views)
Reply With Quote
  #3  
Old 06-28-2004, 09:46 PM
pyang pyang is online now
Registered User
 
Join Date: 12-23-2003
Posts: 33
I've tried the above and the result is no replacements made in file.

Why is it so??

I'm actually trying to update some SQL statement in the text file.
Update String SET Name='Blahblah1234' WHERE String='String1'

Pls advice. Thank you.
Reply With Quote
  #4  
Old 06-28-2004, 10:17 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Typo in there (missing alternation operator). The attachment has been updated with a fix.
Reply With Quote
  #5  
Old 06-28-2004, 10:31 PM
pyang pyang is online now
Registered User
 
Join Date: 12-23-2003
Posts: 33
Ok now it shows Replacement(s) made in file. But it only update the first item with the desired vaue and the other value is blank! The whole sentence is being replaced by an empty line!

Is this method only for 2 replacements?
How to go for more than 2 replacements at one time?

Thank you.
Reply With Quote
  #6  
Old 06-28-2004, 10:39 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
This is the (expected) output I get for the sample:

6/28/2004 9:36:22 PM: Building project step 'Show file'...
File now contains:
...
String1=Testing 1234
String2=blah 456
...
6/28/2004 9:36:23 PM: Building project step 'Replace values'...
Replacement(s) made in file
6/28/2004 9:36:23 PM: Building project step 'Show file'...
File now contains:
...
String1=Testing 0987
String2=blah 122
...


You can have more expressions connected with the alternation operator, just make sure to match the ?n number in the replacement field as needed. See the Replace in File help topic for links to more regex reference documentation.
Reply With Quote
  #7  
Old 06-28-2004, 11:08 PM
pyang pyang is online now
Registered User
 
Join Date: 12-23-2003
Posts: 33
I'm getting the result with afew carriage return after each replacement.

Each time i run the script, the number of carriage return will increase.

But when i run your attached script it is fine.
Reply With Quote
  #8  
Old 06-29-2004, 03:08 AM
pyang pyang is online now
Registered User
 
Join Date: 12-23-2003
Posts: 33
I know why mine is different from yours.
for every replacement i did it in the next line. Therefore i'm getting the additional carriage returns for the number of replacement that i've done.

Thank you.
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 03:42 PM.


Copyright © 1999-2023 Kinook Software, Inc.