Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seek position in text file

Status
Not open for further replies.

VDavid

Programmer
Sep 14, 2003
118
VE
Hi,

In a existing text file, I need to replace one line with something else. Is there a way to do this in VBScript.

For example, the file is

first line
second line
third line
...

What I want to do is modify the file so it will look like

this was the first line
second line
third line
....

Thanks in advanced.
 
There is no rewrite method in the FileSystemObject model.
Either read the input file writing the modified line(s) to an another output file,
or read the entire file, close it, reopen it for output and write the new contents.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Read the whole file into a string, replace the desired characters, then write it back out. If you're replacing one line in a sequential file, then you can split the lines into an array, replace the individual string with whatever text you want, and write it all back out, replacing the original.

But, like PHV and JohnYingling said, you can't do this directly in the file.

Lee
 
PHV, JohnYingling and trollacious thanks for the reply.

I was already thinking in read the entiry file, but I was hoping not to do this.

Thanks all.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top