read string in text file?

wilmoslee

Member
Joined
Mar 12, 2010
Messages
9
Programming Experience
1-3
Hi prof..

I hv a question in urgent.. may i know how can i read string from the text file??

Format is :
Header : have 8 columns in total
Line: Have 15 columns in total.

Both are delimiter by using "|" .

Many many thanks in adv....
 
It would probably look something like this:

VB.NET:
Dim sr as New System.IO.StreamReader(Filename)
Dim line as string = sr.Readline()
While Not line Is Nothing

For each str as String in line.split("|")
   'loop through all columns or just do  line.split("|")(0) to get first column
Next
line = sr.readline()
End While

I was a little confused by the 8 and 15 but that it how you loop through each line and each column of a pipe delimited text file.
 
Hi thx!

I hv work out the code myself like this:

Dim sInput As String = System.IO.File.ReadAllText(path)
Dim sRecord() As String = sInput.Split(";")

For i As Integer = 0 To sRecord.Length - 1

Dim sRecord3() As String = sRecord(i).Split("|")

For n As Integer = 0 To sRecord3.Length - 1
Dim o As String
o = sRecord3(n)

MessageBox.Show(n, o)
Next
Next

thanks
 
Back
Top