Replace a string, in a file, with another string, but..

Deposition
09-26-2004, 09:57 AM
I know how to replace a specific word, or words in a file, but how would I replace an entire line in a file if I only know the first word of the line (and that is the only instance of the word in the file)?

webbone
09-26-2004, 11:05 AM
I know how to replace a specific word, or words in a file, but how would I replace an entire line in a file if I only know the first word of the line (and that is the only instance of the word in the file)?
Are you referring to a text file, where each line is delimited by vbCrLf? If so you should be able to scan the file a line at a time using LineInput - inspect each line as you go either writing it out to a new file unchanged, modifying it and writing it out, or just skipping it and moving on to the next line in the source file.

You could also read the entire file into a string, use Split() with vbCrLf as the delimiter to create an array, scan the array for your "target" lines making changes as needed and then write the array back out to a file.

There are several ways to accomplish this but I think you get the general idea. Specifically, check out LineInput on MSDN: http://msdn.microsoft.com/library/en-us/vbenlr98/html/vastmLineInput.asp

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum