Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


replace line in file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,57462
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> replace line in file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 replace line in file - 3/4/2008 9:23:43 PM   
  Birdy

 

Posts: 5
Score: 0
Joined: 3/4/2008
Status: offline
Hello,

i would like to replace some string in a file with vbscript
for example the file contains a string (BANANA) and i search for BAN the i want that ban overwrite the whole line in the file
also i want to no how a vbscript can copy hisself to another vbs file

thanks
 
 
Post #: 1
 
 RE: replace line in file - 3/4/2008 9:40:30 PM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
I am trying to udnerstand what you are asking for...
To test for the presence of a string inside another string, use InStr().

      

To replace text in a string, use Replace()


      

That gives an output of

how were you world?



_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to Birdy)
 
 
Post #: 2
 
 RE: replace line in file - 3/4/2008 10:17:49 PM   
  Birdy

 

Posts: 5
Score: 0
Joined: 3/4/2008
Status: offline
hello thanks for response
i mean
if iam searching for (wor) in a file
and the string in the file is (hello world)
then (wor) will replace the whole (hello world) string
so after there is only the string (wor) on that line

i hope you understand

< Message edited by Birdy -- 3/4/2008 10:19:27 PM >

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 3
 
 RE: replace line in file - 3/5/2008 1:03:55 AM   
  Birdy

 

Posts: 5
Score: 0
Joined: 3/4/2008
Status: offline
anybody or is my explanation to complicated?

(in reply to Birdy)
 
 
Post #: 4
 
 RE: replace line in file - 3/5/2008 1:48:50 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: online
When you say "and the string in the file is (hello world)"

Do you mean the line in the file is "hello world" and that you want to replace that line with wor?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Birdy)
 
 
Post #: 5
 
 RE: replace line in file - 3/5/2008 1:59:09 AM   
  Birdy

 

Posts: 5
Score: 0
Joined: 3/4/2008
Status: offline
yes if (wor) is detected in the string it will replace the whole line

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: replace line in file - 3/5/2008 2:04:49 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: online
Ok, load the file into an array of the lines in the file. Go through the array and if an item in the array contains wor, then change the item to be whatever you want it to be. After you get through all of the items in the array, write the array back out to the file overwriting the previous file contents.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Birdy)
 
 
Post #: 7
 
 RE: replace line in file - 6/26/2008 11:55:54 PM   
  4scriptmoni


Posts: 203
Score: 0
Joined: 5/3/2007
Status: offline
I have a function that does just that

      

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to Birdy)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> replace line in file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts