|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading block of text from fileFirst my code: Public Class Parser Public Sub New(ByVal fs As String) Dim sr As StreamReader sr = My.Computer.FileSystem.OpenTextFileReader(fs) Dim strLine As String Dim outLine As String Dim lineCount As Short outLine = "" strLine = sr.ReadLine() Do Until strLine = "-}" outLine = outLine + strLine MsgBox(strLine) strLine = sr.ReadLine() Loop MsgBox(outLine) sr.Close() End Class The problem is, that the length of the text block is unknown. I only know for sure, that each block is separated from the next one by two chars "-}" in line. My code read first block, I've got my outLine variable (I will pass it to another object, parse and load into database), but I don't how to continue parsing my file starting from the line after "-}" line. Change the loop and the way you detect the break:
'Read the first line from the file strLine = sr.ReadLine() 'Keep looping untlil the end of the file While strLine IsNot Nothing If strLine = "-}" Then 'We hit the break so 'display the block thus far and 'clear the collector variable ready ' for the next block MsgBox(outLine) outLine = String.Empty Else 'No a break so 'display the line and append it 'to the collector variable MsgBox(strLine) outLine &= strLine End If 'Read the next line from the file strLine = sr.ReadLine() End While sr.Close() Show quoteHide quote "Przemek" <prz***@gmail.com> wrote in message news:1144763716.592062.175190@i39g2000cwa.googlegroups.com... > Hi, I'm trying to parse some text file, which contain blocks of text. > First my code: > > Public Class Parser > Public Sub New(ByVal fs As String) > Dim sr As StreamReader > sr = My.Computer.FileSystem.OpenTextFileReader(fs) > Dim strLine As String > Dim outLine As String > Dim lineCount As Short > > outLine = "" > strLine = sr.ReadLine() > Do Until strLine = "-}" > > outLine = outLine + strLine > MsgBox(strLine) > strLine = sr.ReadLine() > Loop > MsgBox(outLine) > sr.Close() > End Class > > The problem is, that the length of the text block is unknown. I only > know for sure, that each block is separated from the next one by two > chars "-}" in line. My code read first block, I've got my outLine > variable (I will pass it to another object, parse and load into > database), but I don't how to continue parsing my file starting from > the line after "-}" line. >
Saving Jpeg/Exif info Please Help.
Total VB.Net newbie - Directory.Exists question How do I extend My.Resources System.Timers.Timer.Elapsed event not firing simple queue How to simplifying boolean algebra expression? How do I find and use a Window Handle? "Looksalike" algorithm How to simplifying boolean algebra expression? Error connectiong to database |
|||||||||||||||||||||||