I'm not sure the best way to perform this task. I'm trying to read through a text file, parsing out certain lines. However, my Do...While loop looks for the StreamReader.ReadLine <> Nothing when it closes the loop.
The text files I'm parsing have lines with nothing on them, which will cause it to quit early not reading in the whole file. Is there anyway to have it read the number of lines and loop through that way? Or does anyone see another way to do this? My code follows... (just for reference, I'm deleting any line containing a certain string, and the following line)
Code:Function ParseMe(ByVal strFileName As String, ByVal searchString _ As String) Dim objReader As StreamReader Dim objWriter As StreamWriter Dim noWrite As Integer Dim fileDelete As File Dim fileCopy As File ' Open the file objReader = New StreamReader(strFileName) objWriter = New StreamWriter(strTempFile, False) ' Declare variable Dim strLine As String, strData As String ' Loop through, compare, write temp... Do strLine = objReader.ReadLine If strLine <> Nothing Then If strLine.IndexOf(searchString) > 0 Then objReader.ReadLine() noWrite = 1 Else noWrite = 0 End If End If If noWrite = 0 Then objWriter.WriteLine(strLine) End If Loop While strLine <> Nothing objReader.Close() objReader = Nothing objWriter.Close() objWriter = Nothing fileCopy.Copy(strTempFile, strFileName, True) fileDelete.Delete(strTempFile) End Function




Reply With Quote