![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | read text file - but starting at a specific point (not the very first character of the very first line) Good afternoon! Okay - hopefully a simple solution to this seemingly simple question (but above my 'skill set'). We have a bunch of text files - plain, vanilla, everyday text files. There is a specific 'phrase' that shows up (not ever in the same place twice). What we want to do is to (a) find that phrase and (b) start reading the text file from that point on. And, the phrase (Executive Summary) is not necessarily going to be used 15 times in every text file. It *should* appear just once. But, to mitigate any issues, I would like to start reading the text file at the first instance of the phrase. Thanks all! Cary |
My System Specs![]() |
| | #2 (permalink) |
| | Re: read text file - but starting at a specific point (not the very first character of the very first line) Cary Shultz wrote: Quote: > Okay - hopefully a simple solution to this seemingly simple question (but > above my 'skill set'). > > We have a bunch of text files - plain, vanilla, everyday text files. > There is a specific 'phrase' that shows up (not ever in the same place > twice). > > What we want to do is to (a) find that phrase and (b) start reading the > text file from that point on. > > And, the phrase (Executive Summary) is not necessarily going to be used 15 > times in every text file. It *should* appear just once. But, to mitigate > any issues, I would like to start reading the text file at the first > instance of the phrase. InStr function to search for the phrase. You can either read the entire file at once (using the ReadAll method of the file object), or read one line at a time (using the ReadLine method). I think you need to read one line at a time until you find the phrase. Once the phrase is found, process all subsequent lines. In brief: ========= Option Explicit Dim strFile, objFile, strLine, objFSO, strPhrase, blnFound Const ForReading = 1 strPhrase = "Executive Summary" strFile = "c:\Scripts\Report.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, ForReading) blnFound = False Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If (blnFound = True) Then ' Process subsequent lines as desired. End If If (InStr(strLine, strPhrase) > 0) Then ' Phrase found. blnFound = True End If Loop objFile.Close -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How to read the LAST NON-BLANK line from a text file? | VB Script | |||
| Read a line from a text file, without loading the entire file inmemory | PowerShell | |||
| Howto: Add lines of text from a specific point in a text file.. | VB Script | |||
| The next line in a text file | PowerShell | |||
| How do I read a text file and sort text by fixed positions? | PowerShell | |||