473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Reading block of text from file

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.

Apr 11 '06 #1
2 3066
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()

"Przemek" <pr****@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.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.

Apr 11 '06 #2
Thanks for help, now it works!

Przemek

Apr 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: adpsimpson | last post by:
Hi, I have a file which I wish to read from C++. The file, created by another programme, contains both text and numbers, all as ascii (it's a .txt file). A sample of the file is shown below: <<...
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
7
by: John Dann | last post by:
I'm tripping over a silly little problem when trying to read a text file, but can't see the fix. Outline code is: ---------------------------------------------------- FS=New FileStream(filename,...
3
by: lizii | last post by:
i have a file - which on each line has some data i need to fill into a box - now although reading in the data is simple enough and putting it in the correct box will be no problem, as i can just...
13
by: sugard | last post by:
Abstract Class, Inheritance, Polymorphism, File Handling, Exception Handing A program is to be devised for a university to work out whether or not, a student or a professor, is outstanding. The...
1
by: ndedhia1 | last post by:
I was reading in a log file like this that had no milliseconds: QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size QuoteBlockTiming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.